Chris Rebert wrote:
On Mon, Dec 15, 2008 at 11:06 AM, Reckoner recko...@gmail.com wrote:
Hi,
I have lists of the following type:
[1,2,3,[5,6]]
and I want to produce the following strings from this as
'0-1-2-3-5'
'0-1-2-3-6'
That was easy enough. The problem is that these can be
bearophileh...@lycos.com writes:
I was waiting to answer because so far I have found a bad-looking
solution only. Seeing there's only your solution, I show mine too. It
seems similar to your one.
I think that the solution below is a bit clearer, although I think it is
more resource intensive
Hi,
I have lists of the following type:
[1,2,3,[5,6]]
and I want to produce the following strings from this as
'0-1-2-3-5'
'0-1-2-3-6'
That was easy enough. The problem is that these can be nested. For
example:
[1,2,3,[5,6],[7,8,9]]
which should produce
'0-1-2-3-5-7'
'0-1-2-3-5-8'
On Mon, Dec 15, 2008 at 11:06 AM, Reckoner recko...@gmail.com wrote:
Hi,
I have lists of the following type:
[1,2,3,[5,6]]
and I want to produce the following strings from this as
'0-1-2-3-5'
'0-1-2-3-6'
That was easy enough. The problem is that these can be nested. For
example:
At 2008-12-15T19:06:16Z, Reckoner recko...@gmail.com writes:
The problem is that I don't know ahead of time how many lists there are or
how deep they go. In other words, you could have:
Recursion is your friend.
Write a function to unpack one sublist and call itself again with the new
list.
At 2008-12-15T20:03:14Z, Chris Rebert c...@rebertia.com writes:
You just need a recursive list-flattening function. There are many
recipes for these. Here's mine:
flattened = flatten([1,2,3,[5,6,[10, 11]],7,[9,[1, 2, 3, 4, 5 ]]])
flattened
[1, 2, 3, 5, 6, 10, 11, 7, 9, 1, 2, 3, 4, 5]
Reckoner recko...@gmail.com writes:
Hi,
I have lists of the following type:
[1,2,3,[5,6]]
and I want to produce the following strings from this as
'0-1-2-3-5'
'0-1-2-3-6'
That was easy enough. The problem is that these can be nested. For
example:
[1,2,3,[5,6],[7,8,9]]
which
Kirk Strauser wrote:
At 2008-12-15T19:06:16Z, Reckoner recko...@gmail.com writes:
The problem is that I don't know ahead of time how many lists there are or
how deep they go. In other words, you could have:
Recursion is your friend.
Write a function to unpack one sublist and call itself
Arnaud Delobelle:
Here is a not thought out solution:
...
I was waiting to answer because so far I have found a bad-looking
solution only. Seeing there's only your solution, I show mine too. It
seems similar to your one.
def xflatten(seq):
if isinstance(seq, list):
stack =
On Mon, Dec 15, 2008 at 12:24 PM, Kirk Strauser k...@daycos.com wrote:
At 2008-12-15T20:03:14Z, Chris Rebert c...@rebertia.com writes:
You just need a recursive list-flattening function. There are many
recipes for these. Here's mine:
flattened = flatten([1,2,3,[5,6,[10, 11]],7,[9,[1, 2, 3,
On Dec 15, 1:28 pm, Arnaud Delobelle arno...@googlemail.com wrote:
Reckonerrecko...@gmail.com writes:
Hi,
I have lists of the following type:
[1,2,3,[5,6]]
and I want to produce the following strings from this as
'0-1-2-3-5'
'0-1-2-3-6'
That was easy enough. The problem is that
11 matches
Mail list logo