0

I need help to fix this code

list = [] word = “word” for letter in word: list = list + [letter] print (list) output——->[] must output—>[‘w’, ‘o‘ , ‘r’ , ‘d’]

10th Jun 2019, 5:06 PM
GUUKMER_plays
GUUKMER_plays - avatar
3 ответов
+ 7
list = list + [letter] is not working. use: list.append(letter) In general you should not use object names like list as names for variables and so on. if you would have followed this rule, your code would work: list1 = [] word = "word" for letter in word: #list.append(letter) list1 = list1 + [letter] print (list1)
10th Jun 2019, 5:12 PM
Lothar
Lothar - avatar
+ 1
Your code is correct. It outputs ['w', 'o', 'r', 'd'] as expected. Run it again and let me know! Edit: Lothar is correct about not using object names as variables.
10th Jun 2019, 5:34 PM
777
777 - avatar
+ 1
print([letter for letter in word]) print(list(word)) for letter in word: lst.append(letter) print(lst) just some suggestions 😃
11th Jun 2019, 3:01 AM
Choe
Choe - avatar