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.