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..

use python slice notation:

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

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

Does Firefox offer AppleScript support to get URL of windows? -

android - How to install packaged app on Firefox for mobile? -