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[pos]+item)

This could be
  retList.extend([word[pos]+item for item in permuteList])
or in Python 2.4 omit the extra brackets:
  retList.extend(word[pos]+item for item in permuteList)

The list comprehension
  lst = [word[pos]+item for item in permuteList]
is equivalent to
  lst = []
  for item in permuteList:
    lst.append(word[pos]+item)

PS Don't get too crazy about eliminating intermediate variables, they can make 
the code more readable.

Kent

_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to