Beginner Question

Alex Martelli aleax at aleax.it
Fri Mar 28 06:11:58 EST 2003


Lee Harr wrote:
   ...
>>       self.cards[i], self.cards[j] = self.cards[j], self.cards[i]
>> 
>> The problem is to rewrite the last line without using a sequence
>> assignment. Everything I've thought of has the result of only inserting
   ...
>         self.cards.insert(i, self.cards.pop(j))

This produces different results from the original, though.  Not clear
to me if the specs include producing exactly the same results as the
original, but, if so, then:

  temp=self.cards[j]; self.cards[j]=self.cards[i]; self.cards[i]=temp

might be the kind of approach the exercise's author had in mind.


Akex





More information about the Python-list mailing list