Python List Comprehension
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])