Is there a way to do this as a list comprehension? def recu(alist, blist=[]):
.... if len(alist)==0: print blist
.... for i in range(len(alist)):
.... blist.append(alist.pop(i))
.... recu(alist, blist)
.... alist.insert(i, blist.pop())
recu(list("abc"))
['a', 'b', 'c']
['a', 'c', 'b']
['b', 'a', 'c']
['b', 'c', 'a']
['c', 'a', 'b']
['c', 'b', 'a']
Cheers
SimonVC
keywords: python recursive permutations algorithm combination jumble 1 4195
"SimonVC" <py****@simon.vc> wrote in message
news:fa**************************@posting.google.c om... Is there a way to do this as a list comprehension?
def recu(alist, blist=[]): ... if len(alist)==0: print blist ... for i in range(len(alist)): ... blist.append(alist.pop(i)) ... recu(alist, blist) ... alist.insert(i, blist.pop()) recu(list("abc"))
['a', 'b', 'c'] ['a', 'c', 'b'] ['b', 'a', 'c'] ['b', 'c', 'a'] ['c', 'a', 'b'] ['c', 'b', 'a']
Cheers SimonVC
keywords: python recursive permutations algorithm combination jumble
Perhaps this cookbook recipe would be of help to you: http://aspn.activestate.com/ASPN/Coo.../Recipe/204297
It describes how to access the current list comp from within the list comp
itself.
-- Paul This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Fuzzyman |
last post by:
Pythons internal 'pointers' system is certainly causing me a few
headaches..... When I want to copy the contents of a variable I find
it impossible to know whether I've copied the contents *or*...
|
by: Moosebumps |
last post by:
Does anyone here find the list comprehension syntax awkward?
I like it because it is an expression rather than a series of statements,
but it is a little harder to maintain it seems.
e.g. you...
|
by: Steve Goldman |
last post by:
Hi,
I am trying to come up with a way to develop all n-length permutations of a
given list of values. The short function below seems to work, but I can't
help thinking there's a better way. ...
|
by: Timothy Babytch |
last post by:
Hi all.
I have a list that looks like , , ]
I try to make it flat one:
How can I archieve such an effect with list comprehension?
Two cycles did the job, but that way did not look pythonic.....
|
by: Jon Slaughter |
last post by:
#pragma once
#include <vector>
class empty_class
{
};
template <int _I, int _J, class _element, class _property>
class RDES_T
{
| |
by: jena |
last post by:
hello,
when i create list of lambdas:
l=]
then l() returns 'C', i think, it should be 'A'
my workaround is to define helper class with __call__ method:
class X:
def __init__(self,s): self.s=s...
|
by: a |
last post by:
can someone tell me how to use them
thanks
|
by: Gregory Guthrie |
last post by:
Sorry for a simple question- but I don't understand how to parse this use of
a list comprehension.
The "or" clauses are odd to me.
It also seems like it is being overly clever (?) in using a...
|
by: cesco |
last post by:
Hi,
I have a dictionary of lists of tuples like in the following example:
dict = {1: ,
2: ,
3: ]
In this case I have three lists inside the dict but this number is
known only at runtime. I...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |