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

Списъчни разбивки


List Comprehensions е много мощен инструмент, който създава нов списък на базата на друг списък, в един ред, който е лесен за четене.

Например, да кажем, че трябва да създадем списък от цели числа, които указват дължината на всяка дума в дадено изречение, но само ако думата не е "the".

Използвайки list comprehension, можем да опростим този процес до следната нотация:

Exercise

С помощта на list comprehension, създайте нов списък, наречен "newlist", от списъка "numbers", който съдържа само положителните числа от списъка, като цели числа.

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