Python data structure practice problem

1.Create a list by picking an odd-index items from the first list and even index items from the second list

l1 = [3, 6, 9, 12, 15, 18, 21]
l2 = [4, 8, 12, 16, 20, 24, 28]

lst1 = [3, 6, 9, 12, 15, 18, 21]
lst2 = [4, 8, 12, 16, 20, 24, 28]
main_lst =[]

for i in range(len(lst1)):
    if i%2 !=0:
        main_lst.append(lst1[i])
for i in range(len(lst2)):
    if i %2 ==0:
        main_lst.append(lst2[i])
print(main_lst) 

````
1 Like

lst1 = [3, 6, 9, 12, 15, 18, 21]
lst2 = [4, 8, 12, 16, 20, 24, 28]
odd_index=lst1[1::2]
even_index=lst2[0::2]
print(“odd_index elements=”,odd_index ,“even index elements=”,even_index);
final=list()
final.extend(odd_index)
final.extend(even_index)
print(final);

very good. keep practicing.