[Tutor] making a random list, then naming it

Jim Mooney cybervigilante at gmail.com
Fri May 24 04:39:33 CEST 2013


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.

I got as far as making the list, but my brain is fozzled on changing
the numbers entered into part of a data name. Feels like I have to go
outside the program to do it:

import random
random.seed

listparameters = raw_input('\nEnter two numbers, space separated, for
the length and largest value of a zero-starting random list, which can
be used as variable name:  randlist.list_len_max , where len is the
list length you entered, and max is the largest value\n')

listargs = listparameters.split()
rlist = []
length = int(listargs[0])
maxval = int(listargs[1])
for r in range(0,length):
    rlist.append(random.randint(0,maxval))

listlenmax = 'list' + '_' + str(length) + '_' + str(maxval)   # just
the name of a string, not the data name I want

#just printing the below as a test - they'll be removed when the import works

print
print rlist
print
print listlenmax

-- 
Jim Mooney


More information about the Tutor mailing list