assistance with python coding

Richard Morello richard at sneakerfish.com
Mon Sep 11 12:52:25 EDT 2006


Dear John,
 
This is a switch.  In other words if you have two variables, a and b, switch
the values.  The author of the exercise is trying to point out that without
the sequence operation, you must do it the same way as in nearly all other
languages.  That is:
 
tmp = a
a = b 
b = tmp
 
Python gives you the ability to switch two variables with just a single
statement.  To perform the above with a sequence assignment would be:
 
a, b = b, a
 
Your example only slightly complicated this by using an array.  The answer
you are looking for is:
 
tmp = self.cards[i]
self.cards[i] = self.cards[j]
self.cards[j] = tmp
 
Let me know if you need any more help!
 
Yours truly,
Richard Morello
 
-----Original Message-----
From: python-list-bounces+richard=sneakerfish.com at python.org
[mailto:python-list-bounces+richard=sneakerfish.com at python.org] On Behalf Of
John Shappell
Sent: Monday, September 11, 2006 12:23 PM
To: python-list at python.org
Subject: assistance with python coding


I don't understand what this question is asking; can you clarify for me and
maybe point me in the right direction?
 
As an exercise, rewrite this line of code without using a sequence
assignment. 
self.cards[i], self.cards[j] = self.cards[j], self.cards[i]
 
V/R
 
CW2 John Shappell
931-980-4707
FAX 775-618-2455
john.j.shappelljr at us.army.mil
 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20060911/ad08c1cc/attachment.html>


More information about the Python-list mailing list