Re: [Tutor] Better way to insert items into a list

2012-12-09 Thread eryksun
On Sun, Dec 9, 2012 at 4:48 AM, Peter Otten <__pete...@web.de> wrote: > def interleave(items, separator): > ... for item in items: > ... yield item > ... yield separator > ... +1 for this solution if a generator function is desired. It only requires basic Python sy

Re: [Tutor] Better way to insert items into a list

2012-12-09 Thread Peter Otten
Mike wrote: > Hello everyone, > > I was wondering if someone could show me a better way to achieve what > I am trying to do. Here is my test code: > > d=[] > c="00" > a="A,B,C,D" > b=a.split(',') > for item in b: > d.append(item) > d.append(c) > print tup

Re: [Tutor] Better way to insert items into a list

2012-12-08 Thread eryksun
On Sat, Dec 8, 2012 at 7:18 PM, Steven D'Aprano wrote: > > from itertools import izip_longest > def longmux(*iterables, **kwargs): > # This is much easier in Python 3. For comparison, here it is in 3.x with fillvalue as a keyword-only argument: from itertools import zip_longest def

Re: [Tutor] Better way to insert items into a list

2012-12-08 Thread Steven D'Aprano
On 09/12/12 10:45, Mike wrote: Thank you. Works well. Actually, no, it doesn't work well. You only think it works well because you've only tested it with tiny amounts of data. On Sat, Dec 8, 2012 at 4:18 PM, bob gailer wrote: tuple(sum([list(x) for x in zip(a,[c]*len(a))],[])) If you t

Re: [Tutor] Better way to insert items into a list

2012-12-08 Thread Steven D'Aprano
On 09/12/12 06:39, Mike wrote: Hello everyone, I was wondering if someone could show me a better way to achieve what I am trying to do. Here is my test code: d=[] c="00" a="A,B,C,D" b=a.split(',') for item in b: d.append(item) d.append(c) print t

Re: [Tutor] Better way to insert items into a list

2012-12-08 Thread Mike
Thank you. Works well. Mike On Sat, Dec 8, 2012 at 4:18 PM, bob gailer wrote: > tuple(sum([list(x) for x in zip(a,[c]*len(a))],[])) ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/li

Re: [Tutor] Better way to insert items into a list

2012-12-08 Thread bob gailer
On 12/8/2012 2:39 PM, Mike wrote: Hello everyone, I was wondering if someone could show me a better way to achieve what I am trying to do. Here is my test code: d=[] c="00" a="A,B,C,D" b=a.split(',') for item in b: d.append(item) d.append(c) prin

[Tutor] Better way to insert items into a list

2012-12-08 Thread Mike
Hello everyone, I was wondering if someone could show me a better way to achieve what I am trying to do. Here is my test code: d=[] c="00" a="A,B,C,D" b=a.split(',') for item in b: d.append(item) d.append(c) print tuple(d) Basically what I want to end up