list problem

Mark McEahern marklists at mceahern.com
Mon Sep 23 19:06:34 EDT 2002


[jubafre at brturbo.com]
> i have:
> x=[['0020', '0000x9'], ['0030', '0000xa'], ['00B4', '0000x8'],
> ['0030', '0000xb'], ['00F0'], ['0001'], ['0003'], ['0005']]
>
> and i want:
> y=['0020', '0000x9', '0030', '0000xa', '00B4', '0000x8', '0030',
> '0000xb','00F0', '0001',
> '0003', '0005']
>
> how to do this?

You want to flatten a sequence.  Here's a recipe that does that:

  http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/118845

I'll leave it as an exercise for you to deal with the string type
appropriately.  I think the recipe will try to flatten the string (although
I have not tested to confirm that) and that's probably not what you want.

// m

-





More information about the Python-list mailing list