Reputation: 43
I have an application where i read content from a json file, do some formatting and pass the list for another class.
When i print the first item i see this:
['.docx', '.ppt']
And the second is
['.py', '.java', '.cpp']
I append them to a list, but when i print the list this is the result:
[['.docx', '.ppt'], "['.py', '.java', '.cpp']"]
As this is an invalid list, i cant use for my methods who require a list as parameter.
Upvotes: 0
Views: 307
Reputation: 4744
One of the solution is using extract like :
aList = ['.docx', '.ppt']
blist =['.py', '.java', '.cpp']
aList.extend(blist)
print (aList)
Second one is just using +
means :
aList = ['.docx', '.ppt']
blist =['.py', '.java', '.cpp']
aList= aList + blist
print (aList)
Both output :
['.docx', '.ppt', '.py', '.java', '.cpp']
Using extract is more professional
Upvotes: 0