Get started learning Python with DataCamp's free Intro to Python tutorial. Learn Data Science by completing interactive coding challenges and watching videos by expert instructors. Start Now!

This site is generously supported by DataCamp. DataCamp offers online interactive Python Tutorials for Data Science. Join 11 million other learners and get started learning Python for data science today!

Good news! You can save 25% off your Datacamp annual subscription with the code LEARNPYTHON23ALE25 - Click here to redeem your discount

Compresii de liste


List comprehensions sunt un instrument foarte puternic, care creează o listă nouă bazată pe o altă listă, într-o singură linie, ușor de citit.

De exemplu, să presupunem că trebuie să creăm o listă de numere întregi care specifică lungimea fiecărui cuvânt dintr-o anumită propoziție, dar numai dacă cuvântul nu este cuvântul "the".

Folosind o list comprehension, am putea simplifica acest proces la această notație:

Exercițiu

Folosind o list comprehension, creează o listă nouă numită "newlist" din lista "numbers", care conține doar numerele pozitive din listă, ca numere întregi.

This site is generously supported by DataCamp. DataCamp offers online interactive Python Tutorials for Data Science. Join over a million other learners and get started learning Python for data science today!

Previous Tutorial Next Tutorial Take the Test
Copyright © learnpython.org. Read our Terms of Use and Privacy Policy