That python code made me headaches | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
17th Dec 2017, 7:14 AM
Oma Falk
Oma Falk - avatar
14 Answers
+ 10
@Oma you just missed a (, )(separator) in list just place (,) you will get your output sentence = [ 'This', 'is ', 'a' ,'sentence' ]
17th Dec 2017, 7:19 AM
GAWEN STEASY
GAWEN STEASY - avatar
+ 8
Don't know, but I played around with it and it seems you can interchange single for double quotes, as well as docstrings and they all work fine like this. You won't be able to accomodate str() there, however. I assume it is some kind of a shortcut for string concatenation, but works only for implicit strings, not for convertites ;)
17th Dec 2017, 7:49 AM
Kuba Siekierzyński
Kuba Siekierzyński - avatar
+ 7
@ Gawen ... it should be an error
17th Dec 2017, 7:30 AM
Oma Falk
Oma Falk - avatar
+ 7
Cool! 😁 sentence = [ 'a' ' ' 's' 'e' 'n' 't' 'e' 'n' 'c' 'e' ] print(sentence) >>> ['a sentence'] # len == 1
17th Dec 2017, 7:37 AM
Kuba Siekierzyński
Kuba Siekierzyński - avatar
+ 7
@Kuba @Gawen Okay but i am still not happy with it. Why did Guido do THAT???? what does this lout think about how much time I have to become aware of this ???
17th Dec 2017, 7:44 AM
Oma Falk
Oma Falk - avatar
+ 7
@Kuba okay this is a nice application for it. a clear case for submitting a challange isnt it?
17th Dec 2017, 7:59 AM
Oma Falk
Oma Falk - avatar
+ 7
@Kuba sir explained well it seems like python interpreter understand the gap between two string by only by seperater (,) unless it is not interprete the space like print('red' 'yellow') output=> redyellow if I am wrong please correct me @Kuba sir @oma😊😊
17th Dec 2017, 8:01 AM
GAWEN STEASY
GAWEN STEASY - avatar
+ 6
no it will not generate any error because word is separated by (,) so between (,) it will treat it like a word for checking that do like this print(sentence[-1]) last element is output by this which is output as output->asentence
17th Dec 2017, 7:37 AM
GAWEN STEASY
GAWEN STEASY - avatar
+ 5
@Oma If a quiz question, that's gonna be a nasty one ;) Honestly saying, I can't think of any particular reason why it is like so, but perhaps this is more convenient in some cases. Or maybe it is its intrinsic Pythonicness which simplifies everything -- since there is no particular difference between those two versions, let's assume the easier one :)
17th Dec 2017, 8:12 AM
Kuba Siekierzyński
Kuba Siekierzyński - avatar
+ 5
@Gordie Nice find. Good to know! 👍 Seems like the best answer here... 😏
17th Dec 2017, 8:59 AM
Kuba Siekierzyński
Kuba Siekierzyński - avatar
+ 5
thanks for all your answers! There are some nice treasures in python syntax!
18th Dec 2017, 12:01 PM
Oma Falk
Oma Falk - avatar
+ 1
place , between last and second last element
18th Dec 2017, 2:17 PM
BIOSed_Codeboy🎧
BIOSed_Codeboy🎧 - avatar
0
you have forgotten to add a comma between 'a' and 'sentence' so the compiler says the length is 3 instead of 4 as it reads that the array is composed of 3 elements instead of 4
17th Dec 2017, 1:55 PM
Marc Essam
Marc Essam - avatar
0
The last two strings that don't have a separator are taken as one string. When I tried printing the list, the last element was 'asentence'.
19th Dec 2017, 11:51 AM
Technocrat
Technocrat - avatar