Python List Comprehension

Hamdi Yılmaz
Dec 9, 2021

--

[
planet.upper() + '!'
for planet in planets
if len(planet) < 6
]

tek satır hali

def count_negatives(nums):
return len([num for num in nums if num < 0])
print(count_negatives([5, -1, -2, 0, 3]))

boolean kullanımı

def count_negatives(nums):
# Reminder: in the "booleans and conditionals" exercises, we learned about a quirk of
# Python where it calculates something like True + True + False + True to be equal to 3.
return sum([num < 0 for num in nums])

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

No responses yet

Write a response