I don't know list, I not good at list.

Emile van Sebille emile at fenx.com
Wed Jul 13 17:51:38 EDT 2011


On 7/13/2011 2:13 PM Ellerbee, Edward said...
> I've been beating my head against the desk trying to figure out a method
> to accomplish this:
>

<snip>

> #-----------------------------------------------------------------
> My intent is to have the end data come out (from the example list above)
> in the format of
> 25220[56]
> 25224[678]

this should get you started...

 >>> list1=['252205','252246','252206','252247','252248']
 >>> D = {}
 >>> for ii in list1: D.setdefault(ii[:5],[]).append(ii[5])
...
 >>> print D
{'25224': ['6', '7', '8'], '25220': ['5', '6']}
 >>>

Emile




More information about the Python-list mailing list