hi i'm pretty new python, i'm not aware of little tricks , shortcuts yet. have 2 multi-dimensional arrays:
>>> colorstrings [('0', '2371_9890_020'), ('1', '2371_9031_100'), ('2', '2371_9890_464')]
and
>>> skus [('0', '0017651670'), ('0', '0017651688'), ('0', '0017651696'), ('0', '0017651704'), ('0', '0017651712'), ('0', '0017651720'), ('0', '0017651738'), ('1', '0017650896'), ('1', '0017650904'), ('1', '0017650912'), ('1', '0017650920'), ('1', '0017650938'), ('1', '0017650946'), ('1', '0017650953'), ('2', '0017651746'), ('2', '0017651753'), ('2', '0017651761'), ('2', '0017651779'), ('2', '0017651787'), ('2', '0017651795'), ('2', '0017651803')]
basically, want merge these array of dictionary objects. like:
[ { 'colorstring': '2371_9890_020' 'skus': ('0017651670', '0017651688', '0017651696', '0017651704', '0017651712', '0017651720, '0017651738') }, { 'colorstring': '2371_9031_100' 'skus': ('0017650896', '0017650904', '0017650912', '0017650920', '0017650938', '0017650946, '0017650953') }, { 'colorstring': '2371_9890_464' 'skus': ('0017651746', '0017651753', '0017651761', '0017651779', '0017651787', '0017651795, '0017651803') } ]
is there kewl pythonic way of doing using lamba expressions or niftiness? thanks!
try :
result = [ { 'colorstring' : color, 'skus' : [value key, value in skus if key colorkey] } colorkey, color in colorstrings ]
Comments
Post a Comment