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.