python - list comprehension joining every two elements together in a list -


how convert lst1 lst2 joining element 1 element 2 , on.

lst1=[' ff 55 00 90 00 92 00 ad 00 c6 00 b7 00 8d 00 98 00 87 00 8a 00 98 00 8f 00 ca 01 78 03 54 05 bf'] 

to

lst2=[ff55, 0090, 0092, 00ad, 00c6, 00b7, 008d, 0098, 0087, 008a, 0098, 008f, 00ca, 0178, 0354,05bf] 

tried not expiated

   in lst:         lstnew = []         templist =  i.split()         lenlist = len(templist)         #print templist         index = 0         while (index < lenlist):             print templist[index] + templist[index+1]             index = index + 2 

is ok:

>>> lst = ['ff', '55', '00', '90', '00', '92', '00', 'ad',             '00', 'c6', '00', 'b7', '00', '8d', '00', '98',             '00', '87', '00', '8a', '00', '98', '00', '8f',             '00', 'ca', '01', '78', '03', '54', '05', 'bf']  >>> [ ''.join(x) x in zip(lst[0::2], lst[1::2]) ]     ['ff55', '0090', '0092', '00ad', '00c6', '00b7', '008d',       '0098', '0087', '008a', '0098', '008f', '00ca', '0178',       '0354', '05bf'] >>> 

or

>>> [ x+y x,y in zip(lst[0::2], lst[1::2]) ] ['ff55', '0090', '0092', '00ad', '00c6', '00b7',   '008d', '0098', '0087', '008a', '0098', '008f',   '00ca', '0178', '0354', '05bf']   >>> 

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -