Re: [Tutor] Recursion and List Comprehensions

2005-10-28 Thread Carroll, Barry
Andrei: >Date: Sat, 29 Oct 2005 01:13:45 +0200 >From: Andrei <[EMAIL PROTECTED]> >Subject: Re: [Tutor] Recursion and List Comprehensions >To: tutor@python.org >Message-ID: <[EMAIL PROTECTED]> >Content-Type: text/plain; charset=ISO-8859-1; format=flowed <>

Re: [Tutor] Recursion and List Comprehensions

2005-10-28 Thread Carroll, Barry
l, Barry >Sent: Friday, October 28, 2005 5:49 PM >To: 'Alan Gauld'; Carroll, Barry; tutor@python.org >Subject: RE: [Tutor] Recursion and List Comprehensions > >Alan et al: > >After reading the topic you recommended I tried rewriting my permute >function as follows: &

Re: [Tutor] Recursion and List Comprehensions

2005-10-28 Thread Carroll, Barry
ator (retList+= ...) causes this error: >>>>>>>>>> >>> permute.permute3('tests') Traceback (most recent call last): File "", line 1, in ? File "permute.py", line 50, in permute3 retList+=[word[pos]+item for item in perm

Re: [Tutor] Recursion and List Comprehensions

2005-10-28 Thread R. Alan Monroe
> Unfortunately, I don't understand how list comprehensions work and how to > implement them. Can someone point me in the right direction, please. Compare these two pieces of code x=[1,2,3,4] y=[] for eachnum in x: y.append(eachnum * 2) versus x=[1,2,3,4] y = [each * 2 for each in x

Re: [Tutor] Recursion and List Comprehensions

2005-10-28 Thread Andrei
Carroll, Barry wrote: > Greetings: > I'm trying to improve my programming and Python skills. To that end I > have implemented a word jumble program as a recursive function: given a > string of arbitrary length, return a list of all permutations of the > string each character exactly once. In

Re: [Tutor] Recursion and List Comprehensions

2005-10-28 Thread Kent Johnson
Carroll, Barry wrote: >> >>>permuteList=permute2(word[0:pos]+word[pos+1:len(word)]) >> >>># Now, tack the first char onto each word in the list >> >>># and add it to the output >> >>>for item in permuteList: >> >>>retList.append(word[p

Re: [Tutor] Recursion and List Comprehensions

2005-10-28 Thread Alan Gauld
>def permute3 (word): >retList=[] >if len(word) == 1: ># There is only one possible permutation >retList.append(word) >else: ># Return a list of all permutations using all characters >retlist = [a list comprehension that ca

[Tutor] Recursion and List Comprehensions

2005-10-28 Thread Carroll, Barry
Greetings:   I'm trying to improve my programming and Python skills.  To that end I have implemented a word jumble program as a recursive function:  given a string of arbitrary length, return a list of all permutations of the string each character exactly once.  In other words:       pe