Lesson 27 of 34
List Comprehensions: ஒரே வரியில் listList Comprehensions: Lists in One Line
8 min 30 XP
ஒரு list-ஐ loop மூலம் உருவாக்குவதை ஒரே வரியில் எழுதலாம்: [வெளிப்பாடு for உருப்படி in தொகுப்பு]. இது Python-ன் மிகவும் பிரபலமான அம்சம்.
Building a list with a loop can be written in one line: [expression for item in collection]. It's one of Python's most loved features.
Example: edit me and press Run
Press Run to see the result here.கடைசியில் if சேர்த்தால், நிபந்தனை உண்மையானவை மட்டும் சேரும் (filter).
Add an if at the end to keep only the items that match (a filter).
Example: edit me and press Run
Press Run to see the result here.{ } பயன்படுத்தினால் dictionary comprehension. மிக நீளமான comprehension-ஐ சாதாரண loop ஆக எழுதுவதே படிக்க எளிது.
Use { } for a dictionary comprehension. If a comprehension gets very long, a normal loop is easier to read.