On 05/23/2013 10:39 PM, Jim Mooney wrote:
I keep needing random lists of integers for trying things, so I wrote
a small prog I'll import as randlist. The user enters the length and
max val, but then I want the actual data name of the random list
created, to be   list_(length entered)_(max value entered)  as an easy
mnemonic.

<snip>

> print
> print rlist
> print
> print listlenmax
>

By "name of the list" do you mean like the names rlist and listlenmax above? In other words, you want to define an identifier at run time, and bind it to the list object that you have calculated.

And just how would you know you succeeded, unless you already had code that happened to use that same identifier?

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

lists = {}


for .....
    key = 'list' + '_' + str(length) + '_' + str(maxval)
    lists[key] = buildlist(length, maxval)
--
DaveA
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to