Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #4315

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

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!194.109.133.84.MISMATCH!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <iai-gis@sonic.net>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.010
X-Spam-Evidence '*H*': 0.98; '*S*': 0.00; 'happen,': 0.07; 'python': 0.07; '2004': 0.09; 'subject:beginner': 0.09; 'variables.': 0.09; 'pm,': 0.11; 'written': 0.12; 'extension': 0.14; 'modify': 0.14; 'wrote:': 0.14; '"does': 0.16; '1950': 0.16; 'grateful.': 0.16; 'comment:': 0.19; 'template': 0.20; 'language': 0.20; 'programming': 0.20; 'software.': 0.21; 'header:In-Reply-To:1': 0.22; 'subject:question': 0.22; 'loop': 0.22; 'trying': 0.23; 'base.': 0.23; 'structure': 0.24; 'index': 0.25; 'expect': 0.26; 'define': 0.26; 'function': 0.27; 'thanks': 0.29; 'fine.': 0.29; 'beauty': 0.31; 'for,': 0.31; 'list1': 0.31; "can't": 0.31; 'to:addr:python-list': 0.32; 'thank': 0.32; "isn't": 0.34; 'using': 0.34; 'actually': 0.34; 'got': 0.34; 'file': 0.35; 'suggestion': 0.35; 'print': 0.35; 'header:User-Agent:1': 0.35; 'subject:use': 0.35; 'getting': 0.36; 'data': 0.37; 'some': 0.37; 'execute': 0.38; 'steven': 0.38; 'but': 0.38; 'happens': 0.38; 'pdf': 0.38; 'used': 0.38; 'end': 0.39; 'set': 0.39; 'to:addr:python.org': 0.39; 'how': 0.39; 'works': 0.40; 'basic': 0.40; 'map': 0.40; "it's": 0.40; 'subject:Thank': 0.60; 'back': 0.61; 'greetings,': 0.64; 'boss': 0.68; 'deal.': 0.68; 'liked': 0.68; 'subject:You': 0.81; 'habits.': 0.84; 'species': 0.84
Date Fri, 29 Apr 2011 10:43:20 -0700
From Rusty Scalf <iai-gis@sonic.net>
User-Agent Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.15) Gecko/20110303 Lightning/1.0b2 Thunderbird/3.1.9
MIME-Version 1.0
To python-list@python.org
Subject Thank You Re: use of index (beginner's question)
References <4DB8B7F6.9040500@sonic.net>
In-Reply-To <4DB8B7F6.9040500@sonic.net>
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.996.1304099015.9059.python-list@python.org> (permalink)
Lines 67
NNTP-Posting-Host 82.94.164.166
X-Trace 1304099016 news.xs4all.nl 41110 [::ffff:82.94.164.166]:58084
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:4315

Show key headers only | View raw


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
>

Back to comp.lang.python | Previous | Next | Find similar


Thread

Thank You   Re: use of index   (beginner's question) Rusty Scalf <iai-gis@sonic.net> - 2011-04-29 10:43 -0700

csiph-web