regex - Divide list and append the list to separate lists python -
i have list divided 2 parts then, each part have written different lists. code tried here , works fine.
import sys = ['name','2',3,4,5,'a','b','c','d',10,4,'lol','3'] print len(a) list1 =[] list2 = [] in xrange(0, (len(a)/2)): list1.append(a[i]) list2.append(a[(i)+((len(a)/2))]) list2.append(a[(len(a))-1]) print list1 print list2
i know if there other better alternative way this..
a = ['name', '2', 3, 4, 5, 'a', 'b', 'c', 'd', 10, 4, 'lol', '3'] n = len(a) print(n) mid = n // 2 list1, list2 = a[:mid], a[mid:] print(list1) print(list2)
Comments
Post a Comment