python - Joining Lists Within A List? -


i trying make join of lists within list in python here example of doing (the lists bigger in real code):

import itertools  listenv = ["in","vc","vs"] listsize = ["u17-1","u17-2"]  listevnsize = list(itertools.product(listenv, listsize,))  print listevnsize #this results in [('in', 'u17-1'), ('in', 'u17-2'), ('vc', 'u17-1'), ('vc', 'u17-2'), ('vs', 'u17-1'), ('vs', 'u17-2')] 

what want combine inner lists - instance result be:

[('in-u17-1'), ('in-u17-2'), ('vc-u17-1'), ('vc-u17-2'), ('vs-u17-1'), ('vs-u17-2')] 

so in other words join inner lists, when tried using:

listevnsizejoined = '-'.join(map(str,listevnsizezip)) 

as suggested in question, joining of outer lists 1 big string this:

(('in', 'u17-1'),)-(('in', 'u17-2'),)-(('vc', 'u17-1'),)-(('vc', 'u17-2'),)-(('vs', 'u17-1'),) 

final solution:

import itertools  listenv = ["in","vc","vs","vx","rh","ht","dp","ad","pt","ptrh","wp","wprh","cyvx","hm"]; listsize = ["u17-1","u17-2"]; listseventeengr = ["17p:3","17p:4","17p:5.5","17p:7","17p:10","17p:16","17p:22","17p:28","17p:40","17p:49","17p:55","17p:70","17p:100"]   listevnsize = list(itertools.product(listenv, listsize,))  listenvsizejoined = []  x in listevnsize:     listenvsizejoined.append('-'.join(i in x))  print listenvsizejoined 

this final solution combining 2 lists in combinations, , joining inner lists dash.

use str.join

s.join(iterable) -> string  return string concatenation of strings in iterable.  separator between elements s.  l = []  x in listevnsize:     l.append('-'.join(i in x)) 

Comments

Popular posts from this blog

jOOQ update returning clause with Oracle -

java - Warning equals/hashCode on @Data annotation lombok with inheritance -

java - BasicPathUsageException: Cannot join to attribute of basic type -