[Tutor] making a random list, then naming it

Dave Angel davea at davea.name
Sat May 25 03:10:22 CEST 2013


On 05/24/2013 08:04 PM, Jim Mooney wrote:

You forgot to give the author attribution on the following paragraph.  I 
happen to recognize my own text, but that's not a nice thing to do. 
Notice above where it says  "Jim Mooney wrote" ?

>> The short answer is that Python is not designed to be able to do such a
>> thing.  You're advised instead to make a dictionary, where the key is the
>> name you generate
>
>
> I was probably unclear what I wanted to do. Basically, enter a string of
> number pairs of lengths and maxvals to create and print multiple lists, and
> name them, so I could fool around with them and not have to remember each
> one. I noodled around google and found something to do that.

exec and eval can do all sorts of magic.  When there's a different 
answer, that other answer is nearly always preferable.  The problem is 
that once you play this trick to save yourself some keystrokes while 
debugging, you may think you understand the functionality and the risks 
it involves, and use it on code that matters.

As I said, you should make a dictionary.  You can then give names to 
each item in the dictionary, and those names may or may not actually be 
valid identifiers.

Is lists[(3,8)]  really so much harder to type than
     list_3_8  ?

-- 
DaveA


More information about the Tutor mailing list