appending or inserting an item to a list of lists in python -


this question has answer here:

i have list of lists, like

outlist = (['d1', 'd2', 'd3'], ['d4', 'd5', 'd6']) 

i want append ['d7', 'd8', 'd9'] above list

outlist.append(['d7', 'd8', 'd9']) gives me error

traceback (most recent call last):   file "<pyshell#42>", line 1, in <module>     outlist.append(['d7','d8','d9']) attributeerror: 'tuple' object has no attribute 'append' 

outlist.insert(['d7', 'd8', 'd9']) gives me error

traceback (most recent call last):   file "<pyshell#44>", line 1, in <module>     outlist.insert(['d7','d8','d9']) attributeerror: 'tuple' object has no attribute 'insert' 

need in resolving this. want write 'outlist' csv file. how do that?

attributeerror: 'tuple' object has no attribute ... 

that not list, tuple. tuples immutable, therefore there no way want. convert mutable sequence first.

outlist = list(outlist) 

or create list in first place.

(and next time, spend few moments reading error message first.)


Comments

Popular posts from this blog

assembly - 8086 TASM: Illegal Indexing Mode -

Java, LWJGL, OpenGL 1.1, decoding BufferedImage to Bytebuffer and binding to OpenGL across classes -

javascript - addthis share facebook and google+ url -