Classifying two lists and arrange accordingly in python -


i'm working 2 lists looks this:

list_a = [x,y,z,.....]   list_b = [xa,xb,xc,xd,xe,ya,yb,yc,yd,za,zb,zc,zd,ze,zf]   

what i'm trying achieve is, make more lists while arranging data following:

list_x = [x,xa,xb,xc,xd,xe]   list_y = [y,ya,yb,yc,yd]   list_z = [z,za,zb,zc,zd,ze,zf]   

now if use loops like:

final_list=[] item in list_a:     value in list_b:     if value[0] == item:         print item, value 

it filters data can not reach desired format.
guys please give valuable comment on this.
thank you

not 100% formatting, use list of lists.

list_a = ["x","y","z"]   list_b = ["xa","xb","xc","xd","xe","ya","yb","yc","yd","za","zb","zc","zd","ze","zf"]   final_list = [] item in list_a:     item_list = [item]     value in list_b:         if value[0] == item:             item_list.append(value)     final_list.append(item_list) print final_list 

it returns [['x', 'xa', 'xb', 'xc', 'xd', 'xe'], ['y', 'ya', 'yb', 'yc', 'yd'], ['z', 'za', 'zb', 'zc', 'zd', 'ze', 'zf']]


Comments

Popular posts from this blog

java - Suppress Jboss version details from HTTP error response -

gridview - Yii2 DataPorivider $totalSum for a column -

Sass watch command compiles .scss files before full sftp upload -