0

Can someone correct my logic!

Here is the code: words=['cat', 'dog', 'rabbit'] letters=[] for aword in words: for aletter in aword: letters.append(aletter) print(letters) What I do not understand is why " letters.append(aletter)" to me that is like asking python to add letters at the end of the list words. Making ['cat', 'dog', 'rabbit', 'c', 'a', 't', 'd'...] and so on. Append means add an item to a list. Can someone correct my logic?

11th Jan 2017, 1:51 AM
Andrew Rivera
Andrew Rivera - avatar
1 Odpowiedź
0
So... append your letters to words, not letters: words.append(aletter). Logical error, bro :) btw: you don't need letters list at all. If wyou want to keep it, create letters as a copy of words first: letters = words. In that case your code your code will give you expected result, words first and letters after them.
18th Jan 2017, 7:43 PM
Алексей БутылкУс
Алексей БутылкУс - avatar