DEV Community

Mathu varshtih
Mathu varshtih

Posted on

Python : List

List :

Nested Loop - list

for inner_list in l3:

for each_list in inner_list:
    print(each_list, end=' ')
Enter fullscreen mode Exit fullscreen mode

Ternary Operator in List:

l1 = [10,20,30,40.4]
l2 = [30.2,40.3,50,60,70,80,90]

Ternary Operator
small = len(l1) if len(l1) < len(l2) else len(l2)

l3 = []

i = 0
while i < small:
l3.append(l1[i] + l2[i])
i+=1

while i < len(l2):
l3.append(l2[i])
i+=1

print(l3)

Top comments (0)