Fwd: [Tutor] assigning portions of list to another ... thanks
Joseph Paish
jpaish@freenet.edmonton.ab.ca
Tue, 17 Sep 2002 09:47:41 -0600
thanks for all the replies. it's working now.
instead of passing one large merged list to a function, i kept it as the
original several smaller ones and named the variables (using bogus names for
the variables i wouldn't be using) for each individual element in each of the
passed lists.
for example :
nbr1, nbr2, nbr3 = first_record[:]
that way, there was only one line of code for each short list. actually, a
very workable solution.
joe
ps. i am in the process of converting a perl script to python and this is
just the first of what will probably be several "python newbie" questions.
---------- Forwarded Message ----------
Subject: [Tutor] assigning portions of list to another
Date: Mon, 16 Sep 2002 10:23:07 -0600
From: Joseph Paish <jpaish@freenet.edmonton.ab.ca>
To: tutor@python.org
i am trying to copy certain elements from a list into individual variables
without writing one line of code for each assignment of value to variable. i
am missing something that is probably very obvious. i have tried numerous
different combinations of things, and this is the latest:
this is what i have so far:
>>> first_record = [1, 2, 3]
>>> second_rec = [4, 5, 6]
>>> merged_rec = first_record + second_rec
>>> print merged_rec
[1, 2, 3, 4, 5, 6]
(okay so far)
(now to assign certain elements to variable names)
>>> nbr1, nbr2, nbr3 = merged_rec[0, 3, 4]
Traceback (innermost last):
File "<pyshell#15>", line 1, in ?
nbr1, nbr2, nbr3 = merged_rec[0, 3, 4]
TypeError: sequence index must be integer
suggestions? pointers to documentation?
any help would be appreciated
thanks
joe
_______________________________________________
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
-------------------------------------------------------