Python for loop single liner for concatenating 2 strings -


i have implement below pseudo code in python.

dict = {} list1 = [1,2,3,4,5,6] list2 = [2,4,5,7,8] dict['msg'] = "list 2 items not in list 1 : "  x in list 2:    if x in list1:       dict['msg'] += x  <write in log : dict['msg']> 

if use value of msg list

dict['msg'] = ["list 2 items not in list 1 : "] 

i can append values in single liner as

[dict['msg'].append(x) x in l2 if x not in l1] 

but result on output page

msg : [      "list 2 items not in list 1 :",        7,        8       ] 

i want result in single line as

msg : list 2 items not in list 1 : 7,8 

how can achieve that?

not sure why trying use dict here in first place. did same string , list. while printing convert list string.

list1 = [1,2,3,4,5,6] list2 = [2,4,5,7,8] msg = "list 2 items not in list 1 : " exclusion = [ str(i) in list2 if not in list1 ] print msg, ', '.join(x) 

output:

list 2 items not in list 1 : 7, 8


with dict:

list1 = [1,2,3,4,5,6] list2 = [2,4,5,7,8] d['msg'] = "list 2 items not in list 1 : " d['msg'] = [ str(i) in list2 if not in list1 ] print d['msg'] 

output:

'list 2 items not in list 1 : 7, 8'


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -