How can I append the content of each of the following tuples (ie, elements within the list) to another list which already has 'something' in it? So, I want to append the following to a list (eg: result[]) which isn't empty:
l = [('AAAA', 1.11), ('BBB', 2.22), ('CCCC', 3.33)]
Obviously, the following doesn't do the thing:
for item in l:
result.append(item)
print result
I want to printout:
[something, 'AAAA', 1.11]
[something, 'BBB', 2.22]
[something, 'CCCC', 3.33]
You will need to unpack the tuple to append its individual elements. Like this:
You will get this:
You will need to do some processing on the numerical values so that they display correctly, but that would be another question.
You can convert a tuple to a list easily:
And then you can concatenate lists with
extend
:You can use the inbuilt
list()
function to convert a tuple to a list. So an easier version is:Output: