[Tutor] multidemisional arrays

Lloyd Kvam pythonTutor at venix.com
Sat Nov 13 22:39:12 CET 2004


On Sat, 2004-11-13 at 16:06, Diana Furr wrote:
> Please someone help me. I don't know where else to look. I have tried
> everything I've seen to get this to work right but I must be doing
> something wrong. 
> This is the program:
>  
> i=0
> howMany=input('How many artists will you enter? ')
> paintings=[]#painting
> artists=[]#artist
> values=[]#value
> for i in range(0,howMany,1):
>     painting=raw_input('Painting Name ')
>     artist=raw_input('Artist Name ')
>     value=input('Painting Value ')
>     paintings+=[painting]
>     artists+=[artist]
>     values+=[value]
You are doing this step too soon.  These next two lines should be
deferred until you have finished collecting all of your data.  Notice
that you are using artists to store a list of artist names.  And then
you use artists to store the (artist,painting,value) tuples that you
create using zip.
>     artists=zip(artists,paintings,values)
>     artists.sort()
>     i=i+1
(Put them here)
artists=zip(artists,paintings,values)
artists.sort()
> 
> n=0
> for n in range(0,howMany,1):
>     print artists[n]
>  
> I need the program to sort the artists alphabetically. I can do that
> but I'm having trouble with the other lists. When I print it needs to
> look like this:
> Artist    Painting    Value
> Alecia    Flowers    10
> Diana    Apples       15
>  
> When I print it looks like this:
> ('Alecia', 'Flowers', 10)
> (('Diana', 'Apples', 15), 'Apples', 15)
>  
> Why does the , 'Apples', 15) print and how can I loose the parenthesis
> and quotation marks.
> Thanks in advance.
>  
> 
> ______________________________________________________________________
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
-- 
Lloyd Kvam
Venix Corp



More information about the Tutor mailing list