24.05.2025

0

Beğenme

8

Görüntülenme

Proje - Flatten ve Tersine Döndürme

Görev 1

def flatten_list(nested_list):

flat = []

for item in nested_list:

if isinstance(item, list):

flat.extend(flatten_list(item)) # Rekürsif çağrı

else:

flat.append(item)

return flat


input1 = [[1,'a',['cat'],2],[[[3]],'dog'],4,5]

output1 = flatten_list(input1)

print(output1)



Görev 2

def reverse_deep(lst):

reversed_list = []

for item in reversed(lst):

if isinstance(item, list):

reversed_list.append(reverse_deep(item)) # Rekürsif ters çevirme

else:

reversed_list.append(item)

return reversed_list

input2 = [[1, 2], [3, 4], [5, 6, 7]]

output2 = reverse_deep(input2)

print(output2)


Python Temel

Yorumlar

Kullanıcı yorumlarını görüntüleyebilmek için kayıt olmalısınız!

Şen Ekin

console.log('Hello World');

Konum

DE, DE

© 2021 Patika Dev

facebook
twitter
instagram
youtube
linkedin

Disclaimer: The information /programs / events provided on https://patika.dev and https://risein.com are strictly for upskilling and networking purposes related to the technical infrastructure of blockchain platforms. We do not provide financial or investment advice and do not make any representations regarding the value, profitability, or future price of any blockchain or cryptocurrency. Users are encouraged to conduct their own research and consult with licensed financial professionals before engaging in any investment activities. https://patika.dev and https://risein.com disclaim any responsibility for financial decisions made by users based on information provided here.