Type mismatchings and the rank newbie

Kalle Svensson kalle at gnupung.net
Fri Mar 16 17:52:07 EST 2001


Sez John Brawley:
> Rank newbie here, trying to do something specific.
> I need to use a set of numbers (say, 1 to 25), and create 25 lists from the
> numbers (1 thru 25), which lists have a character "P" and a number (one of
> the 25).
> 
> The lists I want look like :
> P1=[x, y, z]
> P2=[x, y, z]
> P3=[x, y, z]
> (etcetera down to P25)
> 
> The user inputs the number that creates the lists, so I can't just write 25
> lists (the number could be anywhere from 13 to 500 or more).

Is there any special reason you can't use a list or a dictionary?

p = []
max = input("How many lists? ")
for i in range(max):
    p.append([x,y,z])
# note that this will create lists from
# p[0] to p[max-1], inclusive.

p = {}
max = input("How many lists? ")
for i in range(max):
    p["P" + str(i+1)] = [x,y,z]
# this will create lists from
# p["P1"] to p["Pmax"], inclusive.

HTH,
  Kalle
-- 
Email: kalle at gnupung.net     | You can tune a filesystem, but you
Web: http://www.gnupung.net/ | can't tune a fish. -- man tunefs(8)
PGP fingerprint: 0C56 B171 8159 327F 1824 F5DE 74D7 80D7 BF3B B1DD
 [ Not signed due to lossage.  Blame Microsoft Outlook Express. ]




More information about the Python-list mailing list