Notifications
Clear all

Python program to Create two lists with first half and second half elements of a list.

   RSS

0
Topic starter

Output Example:
[10,20,30,40,50,60]

[10,20,30]
[40,50,60]

1 Answer
0
Topic starter

lst=[1,2,3,4,5,6,7,8]

n=len(lst)

if(n%2!=0):

    print('list contains odd number of elements')

    exit()

m=int(n/2)

lst1=lst[0:m]

lst2=lst[m:]

print(lst)

print(‘list 1: ’,lst1)

print(‘list 2: ‘,lst2)

Share: