DEV Community

Nuriddin152
Nuriddin152

Posted on • Edited on

Masalalar

list = [3, 6, 9, 12, 15, 18, 20]
list2 = [4, 8, 12, 16, 20, 24, 28]
res = list()
odd_elelements = list[1::2]
print('Element at odd-indeks positsions from list one')
print(odd_elements)

even_elements = list[0::2]
print("even_elements at even-indeks posiysion from list two")
print(even_elements)

print('Priting final third list')
res.extend(odd_elements)
res.extend(even_elements)
print(res)

revers() - bu funksiya biz kiritgan sonlarni tesgarisiga ogirib beradi va ekranga chiqaradi

list1 = [100, 200, 300, 400, 500]
list1.reverse()
print(list1)

solution 2

-1 salbiy kesishdan foydalanish.Shunda biz kiritgan sonlarni teskarisiga ogirib beradi va ekranga chiqaradi

list1 = (300, 400, 500, 600, 700)
list1 = list1[::-1]
print(list1)

tuple1 = (10, 20, 30, 40, 50)
tuple1 = tuple[::-1]

tuple = ("orange",[10, 20, 30],(5, 15, 25))
print(tuple)
print(tuple[1])
print(tuple[2])
print(tuple[1][1])

tuple1 = (11, 22, 33, 44, 55, 66)
tuple2 = tuple1
print(tuple2[3])
print(tuple2[4])
tuple1 = tuple2[3::-1]
print(tuple1)

range ga mashq

x = range(6)

display x:

print(type(x))

dict ga mashq

x = {"name": "John", 'age':36}

display the data type of x:

print(type(x))

set ga mashq

x = ({"Apple", "banana", "cherry"})

display x:

print(x)

display the data type x

print(type(x))

frozenset ga mashq

x = frozenset({"Apple", "Apple", "Cherry"})

display x:

print(x)

diplay the data type of x

print(type(x))

bool ga mashq

x = True

diplay x:

print(x)

display the data type of x:

print(type(x))

bytes ga mashq

x = b"Hello"

display x:

print(x)

display the data type of x:

print(type(x))

Top comments (0)