List comprehension


#1

is there a fixed syntax for list comprehension,

cubes_by_four = [i**3 for i in range(1,11) if i**3%4==0 ]

ok, this syntax i got it ,but for more complex code, i cannot imagine it


#2

This article on DigitalOcean explains the syntax a bit more, including more complex examples: https://www.digitalocean.com/community/tutorials/understanding-list-comprehensions-in-python-3


#3

Also see the following material in the official Python 3 documentation:


#4

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.