[Tutor] [tutor] creating list of tuples
Alan Gauld
alan.gauld at btinternet.com
Tue Feb 26 09:01:44 CET 2008
"Varsha Purohit" <varsha.purohit at gmail.com> wrote
One small point.
> for x in file:
> value=0
> tup = ()
There ia no point in creating an emnpty tuuple. Tuples
are immutable so this tuple will simply be thrown away.
It doesnm't do much harm, but it does no good either.
> for developerAgent in developers:
> #print developerAgent.disutility
> value +=developerAgent.disutility
> tup = (value,globalVar.cntr)
This creates a brand new tuple and is all that is needed.
BTW going by the names used are you sure a list of
tuples is what you need? It looks like maybe a dictionary
could be used instead storing the values against the cntr
as a key. That would perform the role of borth list and
tuple and make retrieval of the values easier later.
Just a thought.
HTH,
--
Alan Gauld
Author of the Learn to Program web site
Temorarily at:
http://uk.geocities.com/alan.gauld@btinternet.com/
Normally:
http://www.freenetpages.co.uk/hp/alan.gauld
More information about the Tutor
mailing list