Python Forum

Full Version: Lists
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Dear friends can you please help me???
vec = [[1,2,3],[4,5,6],[7,8,9,0]]
print([num for elem in vec for num in elem]) **huh** 
what does the second statement meant? Exclamation
It a list expression:
Equal to
vec = [[1,2,3],[4,5,6],[7,8,9,0]]
output = []
for elem in vec:
    for num in elem:
        output.append(num)
print(output)