Gelişmiş Python İşlevleri
Jan 07 2023
.
def get_lengths(words):
return map(len, words)
words = ['cat', 'window', 'defenestrate']
lengths = get_lengths(words)
print(lengths) # [3, 6, 12]
def multiply(x, y):
return x * y
a = [1, 2, 3]
b = [10, 20, 30]
result = map(multiply, a, b)
print(result) # [10, 40, 90]
from functools import reduce
def multiply(x, y):
return x * y
a = [1, 2, 3, 4]
result = reduce(multiply, a)
print(result) # 24
from functools import reduce
def add(x, y):
return x + y
a = [1, 2, 3, 4]
result = reduce(add, a, 0)
print(result) # 10
def is_odd(x):
return x % 2 == 1
a = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
odd_numbers = filter(is_odd, a)
print(odd_numbers) # [1, 3, 5, 7, 9]
a = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
odd_numbers = filter(lambda x: x % 2 == 1, a)
print(odd_numbers) # [1, 3, 5, 7, 9]
a = [1, 2, 3]
b = ['a', 'b', 'c']
zipped = zip(a, b)
print(zipped) # [(1, 'a'), (2, 'b'), (3, 'c')]
a = [1, 2, 3]
b = ['a', 'b', 'c']
c = [True, False, True]
zipped = zip(a, b, c)
print(zipped) # [(1, 'a', True), (2, 'b', False), (3, 'c', True)]
def print_tuples(a, b, c):
print(f'a: {a}, b: {b}, c: {c}')
a = [1, 2, 3]
b = ['a', 'b', 'c']
c = [True, False, True]
zipped = zip(a, b, c)
# Unpack the tuples in a function call
for t in zipped:
print_tuples(*t)
# Unpack the tuples in a list comprehension
unzipped = [print_tuples(*t) for t in zipped]
a = ['a', 'b', 'c']
for i, element in enumerate(a):
print(f'{i}: {element}')
# Output:
# 0: a
# 1: b
# 2: c
a = ['a', 'b', 'c']
for i, element in enumerate(a, 1):
print(f'{i}: {element}')
# Output:
# 1: a
# 2: b
# 3: c
Gene Simmons, KISS Çizgi Romanlarının Potansiyel Olarak "İnsanlığı Yeniden Yaratabileceğini" Söyledi
Donovan, Şarkılarından 1'ini The Beatles'ın "Lucy in the Sky with Diamonds" şarkısıyla karşılaştırdı
Tom Girardi Dolandırıcılık Suçlamalarından Yargılanma Yetkisinin Belirlenmesi İçin Duruşmaya Katıldı
Charly Reynolds Yakın Zamandaki Vokal Kord Ameliyatını Açıkladı: 'Şarkı Söylemekte Sorun Yaşıyordum'

![Bağlantılı Liste Nedir? [Bölüm 1]](https://post.nghiatu.com/assets/images/m/max/724/1*Xokk6XOjWyIGCBujkJsCzQ.jpeg)



































