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


Groups > comp.lang.python > #36082

Re: Question on for loop

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!goblin2!goblin.stu.neva.ru!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <matt.walker.jones@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.002
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'mrab': 0.05; 'that?': 0.05; 'alignment': 0.07; 'assign': 0.07; 'dynamically': 0.07; 'subject:Question': 0.07; 'already.': 0.09; 'here?': 0.09; 'nb:': 0.09; 'yeah,': 0.09; 'apology': 0.16; 'fruit': 0.16; '\xa0what': 0.16; 'wrote:': 0.17; 'thu,': 0.17; 'variables': 0.17; 'jan': 0.18; 'skip:v 30': 0.20; 'trying': 0.21; 'seems': 0.23; 'header :In-Reply-To:1': 0.25; 'creating': 0.26; 'message- id:@mail.gmail.com': 0.27; 'dictionary': 0.29; 'key,': 0.29; 'url:mailman': 0.29; 'this.': 0.29; "i'm": 0.29; 'maybe': 0.29; 'url:python': 0.32; 'print': 0.32; 'url:listinfo': 0.32; 'to:addr :python-list': 0.33; 'received:google.com': 0.34; 'list': 0.35; 'pm,': 0.35; 'received:209.85': 0.35; 'something': 0.35; 'but': 0.36; 'url:org': 0.36; 'bad': 0.37; 'why': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'some': 0.38; 'sure': 0.38; 'to:addr:python.org': 0.39; 'received:209.85.214': 0.39; 'list,': 0.39; 'header:Received:5': 0.40; 'url:mail': 0.40; 'group,': 0.60; 'email addr:gmail.com': 0.63; 'dear': 0.66; 'kindly': 0.67; "'first'": 0.84; '2013': 0.84; 'take,': 0.84
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=gCnhckDsMZPp0MCiDC0gRoFxFW5JnTY7lNEeTXgBAg8=; b=vm6hWiRV6+HrwqFyOT9rsR+Aw/5oofr+YwDVAr72L4T6Mp6SdLX7Zulqjru4fxhhOn +nPg3t8NM/iXOLPFa2fao8tHS8/mCXk1NU2P6IrRmqBk86LGn8UcL+GKWQVPcCPPKb7n 6WqSbokpgt++6l23MDIPAk89wvfmlMRRTjorHALNgg9VR6z0ak+N9TT8FHMlbRQluRkn 9ebQ3vCFqWWO++n8GRx8P2kOpbTZo1uN7WRQcdvNod08yoB9vvmkxuuwb4BreRiHkVti Y0mPrJx4cL1zDpjxKBguhhTqyKT7uVMFzbyZTGnN/yrPpZWRQKi4R1cp0DXhfQ5PDGcJ y+Sg==
MIME-Version 1.0
In-Reply-To <50E5E861.6040000@mrabarnett.plus.com>
References <456df1a1-9225-44e7-9aa9-6b6fe3fde4a0@googlegroups.com> <50E5E861.6040000@mrabarnett.plus.com>
From Matt Jones <matt.walker.jones@gmail.com>
Date Thu, 3 Jan 2013 14:28:06 -0600
Subject Re: Question on for loop
To python-list@python.org
Content-Type multipart/alternative; boundary=e89a8fb206e48d342904d268347e
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
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.59.1357244916.2939.python-list@python.org> (permalink)
Lines 151
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1357244916 news.xs4all.nl 6937 [2001:888:2000:d::a6]:39608
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:36082

Show key headers only | View raw


[Multipart message — attachments visible in raw view] - view raw

Yeah, this seems like a bad idea.  What exactly are you trying to do here?

Maybe using a dictionary is what you want?


d = {
    'first' : 'banana',
    'second' : 'apple',
    'third'  : 'mango'
}

for key, value in d.items():
    print key, value


However I'm still not sure why you'd want to do this.

*Matt Jones*


On Thu, Jan 3, 2013 at 2:21 PM, MRAB <python@mrabarnett.plus.com> wrote:

> On 2013-01-03 20:04, subhabangalore@gmail.com wrote:
>
>> Dear Group,
>> If I take a list like the following:
>>
>> fruits = ['banana', 'apple',  'mango']
>> for fruit in fruits:
>>     print 'Current fruit :', fruit
>>
>> Now,
>> if I want variables like var1,var2,var3 be assigned to them, we may take,
>> var1=banana,
>> var2=apple,
>> var3=mango
>>
>> but can we do something to assign the variables dynamically I was thinking
>> of
>> var_series=['var1','var2','**var3']
>> for var in var_series:
>>    for fruit in fruits:
>>         print var,fruits
>>
>> If any one can kindly suggest.
>>
>> Regards,
>> Subhabrata
>>
>> NB: Apology for some alignment mistakes,etc.
>>
>>  Why would you want to do that? Creating names dynamically like that is
> a bad idea. Just keep them in a list, like they are already.
> --
> http://mail.python.org/**mailman/listinfo/python-list<http://mail.python.org/mailman/listinfo/python-list>
>

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Question on for loop subhabangalore@gmail.com - 2013-01-03 12:04 -0800
  Re: Question on for loop MRAB <python@mrabarnett.plus.com> - 2013-01-03 20:21 +0000
  Re: Question on for loop Peter Otten <__peter__@web.de> - 2013-01-03 21:22 +0100
  Re: Question on for loop Matt Jones <matt.walker.jones@gmail.com> - 2013-01-03 14:28 -0600
  Re: Question on for loop Don Ross <donrosszx@gmail.com> - 2013-01-03 15:22 -0800
  Re: Question on for loop alex23 <wuwei23@gmail.com> - 2013-01-03 16:47 -0800
  Re: Question on for loop Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-01-04 05:48 +0000
    Re: Question on for loop subhabangalore@gmail.com - 2013-01-15 11:30 -0800
  Re: Question on for loop Alister <alister.ware@ntlworld.com> - 2013-01-04 10:16 +0000

csiph-web