i'm lost in list manipulation
wes weston
wweston at att.net
Wed Mar 3 12:48:23 EST 2004
GrelEns wrote:
> hello,
>
> having a list like ['a', 'b', 'c', 'd'] i would like to get
>
> [['a', '-', 'b', 'c', 'd'],
> ['a', 'b', '-', 'c', 'd'],
> ['a', 'b', 'c', '-', 'd'],
> ['a', '-', 'b', '-', 'c', 'd'],
> ['a', 'b', '-', 'c', '-', 'd'],
> ['a', '-', 'b', '-', 'c','-', 'd']]
>
> that is adding successively an item between at all the available place, and
> i just can't get my brain doing that :(
>
> thank a lot if you could help...
>
>
GrelEns,
Scott has it. For a start string of 4 chars there are 3 gaps/spaces
for the dash/not dash. So, there are 8 possible results. One of these
has no dashes - you may want to throw this one out. The "gap" strings
needs to be:
"000"
"001"
"010"
"011"
"100"
"101"
"110"
"111"
where the 1's are your character; "-"
Throw out the first one and insert into the gaps in the original string.
wes
More information about the Python-list
mailing list