[Tutor] sorting / outputting varibales

Kent Johnson kent37 at tds.net
Thu Nov 1 20:23:33 CET 2007


ted b wrote:
> If i input the following in python:
>    var1 = 7
>    var2 = 9
>    var3 = 5
>    args = [var1, var2, var3]
>    args.sort()
> 
> then if if type:
> 
>    args
> 
> the output is
> 
>    [5, 7, 9]
> 
> but i want the output to be
> 
>    [var3, var1, var2]
> 
> is there a function that will output the variable
> names in the order they have been sorted instead of
> the variable contents themselves?

Questions like this usually indicate that the questioner is on the wrong 
track. What are you trying to do? Probably it can be better done with a 
list or dictionary of values.

Is this a followup to your earlier "sorting variables" question? Evert 
showed you how to do that, is there a problem?

Kent


More information about the Tutor mailing list