Python Training _ 6

WONY_yoon·2025년 10월 12일
post-thumbnail

Sequence Item Selection

apple, kiwi 를 대문자로 출력

x = ["grapes", "mango", "orange", "peach", "apple", "lime", "banana", "cherry", "tomato", "kiwi", "blueberry", "watermelon"]

print([fruit.upper() for fruit in x if fruit in ['apple', 'kiwi']])

<< 떠올리지 못했던 다른 방법들 >>

x = ["grapes", "mango", "orange", "peach", "apple", "lime", "banana", "cherry", "tomato", "kiwi", "blueberry", "watermelon"]

print([fruit.upper() for fruit in x if fruit in ['apple', 'kiwi']])

0개의 댓글