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: 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 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: 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 --e89a8fb206e48d342904d268347e Content-Type: text/plain; charset=ISO-8859-1 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 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 > --e89a8fb206e48d342904d268347e Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
Yeah, this seems like a bad idea. =A0What exactly are you trying to do h= ere?

Maybe using a dictionary is what you want?

=

d =3D {
<= font face=3D"courier new,monospace">=A0 =A0 'first' : 'banana&#= 39;,
=A0= =A0 'second' : 'apple',
=A0 =A0 'third= ' =A0: 'mango'
}

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


However I'm still not sure why you'd want to do th= is. =A0
--e89a8fb206e48d342904d268347e--