python - using split for appending to multiple lists -


is possible combine 2 statements inside 'for' loop.

num_pro=raw_input("enter number of productions: ")  right=[];left=[];  in range(int(num_pro)):    l,r=raw_input("enter production"+str(i+1)+" : ").split('->')    right.append(r);left.append(l) 

sample input: e->abc

append tuples one list, split out lists using zip():

entries = []  in range(int(num_pro)):     entries.append(raw_input("enter production"+str(i+1)+" : ").split('->'))  left, right = zip(*entries) 

zip(*iterable) transposes nested list; columns become rows. because have 2 'columns' (pairs of values), end 2 rows instead.


Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

How to get multiresult with multicondition in Sql Server -