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".
Wha
On Thu, Apr 28, 2011 at 11:42 AM, Rusty Scalf wrote:
> list1 = ['pig', 'horse', 'moose']
> list2 = ['62327', '49123', '79115']
> n = 2
> s2 = "list" + `n`
> a = s2[list1.index('horse')]
> print a
>
> -does not work
While advices above are indeed right way to go in your case, there is
a way to g
On Thu, 28 Apr 2011 01:49:33 +0100, Chris Angelico
wrote:
On Thu, Apr 28, 2011 at 10:42 AM, Rusty Scalf wrote:
list1 = ['pig', 'horse', 'moose']
list2 = ['62327', '49123', '79115']
n = 2
s2 = "list" + `n`
a = s2[list1.index('horse')]
print a
s2 is a string with the value "list2"; this is n
lists instead of strings (Andrew Berg)
> 4. Re: unpickling derived LogRecord in python 2.7 from python2.6
> (Peter Otten)
> 5. Re: Access violation reading 0x0010 (yuan zheng)
> 6. Re: argparse parser stores lists instead of strings (Peter Otten)
> 7. Re: use of index (
On Apr 28, 5:32 am, Algis Kabaila wrote:
> On Thursday 28 April 2011 11:23:51 Thomas 'PointedEars' Lahn
> wrote:> Chris Angelico wrote:
> > > Rusty Scalf wrote:
> > >> list1 = ['pig', 'horse', 'moose']
> > >> list2 = ['62327', '49123', '79115']
> > >> n = 2
> > >> s2 = "list" + `n`
> >>> "list" +
On Apr 28, 2:45 am, Chris Angelico wrote:
> Incidentally, you're allowed to put the comma on the last item too:
>
> lists = [
> ['pig', 'horse', 'moose'],
> ['62327', '49123', '79115'],
> ]
>
> Often makes for easier maintenance, especially when you append
> array/list elements.
>
> Chris Ang
On Thursday 28 April 2011 11:23:51 Thomas 'PointedEars' Lahn
wrote:
> Chris Angelico wrote:
> > Rusty Scalf wrote:
> >> list1 = ['pig', 'horse', 'moose']
> >> list2 = ['62327', '49123', '79115']
> >> n = 2
> >> s2 = "list" + `n`
>>> "list" + 'n'
'listn'
>>>
And IMHO you did not want that, did yo
On Wed, 27 Apr 2011 17:42:30 -0700, 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
>
>
On Thu, Apr 28, 2011 at 11:23 AM, Thomas 'PointedEars' Lahn
wrote:
> You forgot a comma after the first `]', to separate the list elements.
Whoops! Apologies. It's very confusing when example code has silly
bugs in it! And yes, need to either back down the indices or insert a
shim. Memo, to self:
On Wed, Apr 27, 2011 at 6:23 PM, Thomas 'PointedEars' Lahn
wrote:
> Chris Angelico wrote:
>> Rusty Scalf wrote:
>>> list1 = ['pig', 'horse', 'moose']
>>> list2 = ['62327', '49123', '79115']
>>> n = 2
>>> s2 = "list" + `n`
>
> I would prefer the clearer
>
> s2 = "list" + str(n)
>
> or
>
> s2 = "
Chris Angelico wrote:
> Rusty Scalf wrote:
>> list1 = ['pig', 'horse', 'moose']
>> list2 = ['62327', '49123', '79115']
>> n = 2
>> s2 = "list" + `n`
I would prefer the clearer
s2 = "list" + str(n)
or
s2 = "list%s" % n
>> a = s2[list1.index('horse')]
>> print a
>
> s2 is a string with th
On Thu, Apr 28, 2011 at 10:42 AM, Rusty Scalf wrote:
> list1 = ['pig', 'horse', 'moose']
> list2 = ['62327', '49123', '79115']
> n = 2
> s2 = "list" + `n`
> a = s2[list1.index('horse')]
> print a
s2 is a string with the value "list2"; this is not the same as the
variable list2. You could use eva
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', '4912
13 matches
Mail list logo