Lesson 27 of 34

List Comprehensions: ఒకే లైన్‌లో Lists

8 min 30 XP

loop తో list తయారు చేయడాన్ని ఒకే లైన్‌లో రాయవచ్చు: [expression for item in collection]. Python లో అందరికీ ఇష్టమైన ఫీచర్లలో ఇది ఒకటి.

Example: edit me and press Run

Output Loading Python (first time takes a few seconds)
Press Run to see the result here.

చివర if కలిపి సరిపోయే items ను మాత్రమే ఉంచండి (filter).

Example: edit me and press Run

Output Loading Python (first time takes a few seconds)
Press Run to see the result here.

dictionary comprehension కోసం { } వాడండి. comprehension మరీ పొడవైతే సాధారణ loop చదవడానికి సులభం.

Challenge

+30 XP

list comprehension తో 1 నుండి 10 వరకు సరి సంఖ్యల వర్గాలను list గా print చేయండి: [4, 16, 36, 64, 100]

Output Loading Python (first time takes a few seconds)
Press Run to see the result here.