list1=[1,3,5,7,11,13,17,19,23,31,41]
list2=[2,4,6,8,10,12,14,16,18,20,22]
print("toq sonlar:",list1[0:7]) #toq sonlarni chiqar.0-indeksdan 7-indeksgacha.
print("juft sonlar:",list2[0:7]) #juft sonlarni chiqar.0-indeksdan 7-indeksgacha.
list1=[1,3,5,7,11,13,17,19,23,31,41]
list2=[2,4,6,8,10,12,14,16,18,20,22]
res=list() #bu yerda listni res ga tenglab olyapmiz.
odd_elements=list1[1::2]
print("element at odd -index positions from list one ")
print(odd_elements)
even_elements=list2[0::2]
print("element at even -index positions from list two")
print(even_elements)
print("printing final third list")
res.extend(odd_elements)
res.extend(even_elements)
print(res)
solution1
revers()- bu funksiya biza kiritgan sonlarnni teskarisiga ugirib beradi.
list1=[100,200,300,400,500]
list1.reverse() #reverse teskarisiga qilish
print(list1)
tushuntirish :
bu yerda list1 dagi sonlarni teskarisiga chop etib beradi .
solution2
-1 salbiy kesish dan foydalanish shunda biza kiritgan sonlarnni teskarisiga ugirib beradi va edranga chiqarib beradi .
list1=[300,400,500,600,700]
list1=list1[::-1]
print(list1)
list1=(300,400,500,600,700)
list1=list1[0::-1]
print(list1)
tuple1=("orange",[10,20,30],[5,15,25])
print(tuple1)
print(tuple1[0])
print(tuple1[1])
print(tuple1[2])
print(tuple1[1][1])# bu yerda 1 indeksdagi ya'ni[10,20,30]dagi 1-indeks ya'ni 20 ni print qil deyilyapti.
tuple1=(11,22,33,44,55,66)
print(tuple1[3])#44 ni chiqar
print(tuple1[4])#55 ni chiqar
print(tuple1[3])
list1.reverse()
print(list1[3::-1])
print(tuple(2))# 44 dan boshlab teskarisiga o'qi deyilyapti. 11 gacha.
Top comments (0)