Thank You Re: use of index (beginner's question)

Rusty Scalf iai-gis at sonic.net
Fri Apr 29 19:43:20 CEST 2011


An overdue Thank You to everyone who responded.  I got well more than I 
bargained for, including needed reinforcement (beyond the beginner's 
guides) of how Python actually works and some good programming habits. I 
am grateful.

I liked Steven D'Aprano comment:

   Define "does not work".
   What do you expect to happen, and what happens instead?

A good dose of humility. Getting a result that surprises me isn't the 
same as the language not working!

In the end I followed Thomas Lahn's suggestion and used the structure

  data = {
       'pig':   '62327',
       'horse': '49123',
       'moose': '79115'
   }
   print data.get('horse')

I am using the Python extension written for ArcGIS software.

The happy result is a set of 54 maps, each with three frames, which 
display gridded tuna harvest data for 3 tuna species from 1950 through 
2004 as well as total tonnages. And the beauty is, if I modify the basic 
map template I need only execute the program again, go have coffee, and 
come back to 54 new pdf files!  The boss can say 'change the title font' 
and it's no big deal.

Thanks again,
          Rusty Scalf


On 4/27/2011 5:42 PM, Rusty Scalf wrote:
> Greetings,
> I am just now learning python and am trying to use the index function 
> with variables.
>
> list1 = ['pig', 'horse', 'moose']
> list2 =  ['62327', '49123', '79115']
> a = list2[list1.index('horse')]
> print a
> >49123
>
>    -works fine. But
>
> list1 = ['pig', 'horse', 'moose']
> list2 =  ['62327', '49123', '79115']
> n = 2
> s2 = "list" + `n`
> a = s2[list1.index('horse')]
> print a
>
>   -does not work
>
> I'd like to use the index function in a loop updating the file names 
> by adding a number to that name with each cycle. But can't get to 
> first base.
>
> Thank you,
>
>    Rusty Scalf
>




More information about the Python-list mailing list