Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Lists
#1
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
Reply
#2
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)
99 percent of computer problems exists between chair and keyboard.
Reply
#3
And it's called a list comprehension explained here: https://www.programiz.com/python-program...prehension
or here: http://www.pythonforbeginners.com/basics...-in-python
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Split dict of lists into smaller dicts of lists. pcs3rd 3 2,368 Sep-19-2020, 09:12 AM
Last Post: ibreeden
  sort lists of lists with multiple criteria: similar values need to be treated equal stillsen 2 3,264 Mar-20-2019, 08:01 PM
Last Post: stillsen

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020