maybe its just me, but the behavior of parallel lists in for loops seems
backwards. why doesnt it mirror parallel assignment? i think tuple-unpacking
should take precedence, but instead iteration happens along the first
dimension and unpacking comes second, forcing the use of zip. a, b = [1,2,3], [4,5,6] # a = [1,2,3], b = [4,5,6] for a, b in zip([1,2,3], [4,5,6]): print a, b
instead of: for a, b in [1,2,3], [4,5,6]: print a, b # illegal
im sure there is a good reason why the former was chosen, and i know its way
too late to switch, but i cant think of many examples of when you would use
parallel iteration *without* zip. not even dictionaries since you have to
use .items() anyway (another thing that should be default in my mind). of
course, using zip is no big deal but im just curious, from a design
perspective why the choice was made. 2 3380
>>>> a, b = [1,2,3], [4,5,6] # a = [1,2,3], b = [4,5,6] for a, b in zip([1,2,3], [4,5,6]): print a, b instead of: for a, b in [1,2,3], [4,5,6]: print a, b # illegal
im sure there is a good reason why the former was chosen, and i know its way too late to switch, but i cant think of many examples of when you would use parallel iteration *without* zip. not even dictionaries since you have to
dates = [(2004, 4, 27), (2004, 2, 9), (2003, 11, 14)]
for year, month, day in dates:
do_something_with(year)
and_with(month, date)
Also, it's more consistent: in each iteration, an element of the
list being iterated over is assigned to the loop variable; or if
it's multiple variables, automatic unpacking happens just like it
would if a value were assigned to multiple variables in an
assignment statement. > a, b = [1,2,3], [4,5,6] # a = [1,2,3], b = [4,5,6] > for a, b in zip([1,2,3], [4,5,6]): print a, b instead of:> for a, b in [1,2,3], [4,5,6]: print a, b # illegal
im sure there is a good reason why the former was chosen, and i know its
way too late to switch, but i cant think of many examples of when you would
use parallel iteration *without* zip. not even dictionaries since you have
to dates = [(2004, 4, 27), (2004, 2, 9), (2003, 11, 14)] for year, month, day in dates: do_something_with(year) and_with(month, date)
i assume you meant day instead of date on the last line...
Also, it's more consistent: in each iteration, an element of the list being iterated over is assigned to the loop variable; or if it's multiple variables, automatic unpacking happens just like it would if a value were assigned to multiple variables in an assignment statement.
i had thought of something like that, say points:
for x, y, z in points:
but when i really stopped to think about it, it is not more consistent since
(x, y, z) is not a direct member of the points list; its a decomposition of
a single point. likewise, (year, month, day) is a single date. therefore you
should have to say:
for point in points:
x, y, z = point
...
its one more line, but its more explicit. or just use a point class and
access point.x, point.y, and point.z. i guess it comes down to whether
breaking up a single list of tuples is the more common use of parallel
iteration vars, or iterating over multiple iterators with a single var each.
i think its the latter, but maybe thats just the type of problems ive
encountered that dealt with parallel iteration...
as another example, the old problem of including the counter var, only
/satisfactorily/ solved by enumerate(). this is a case where i have to stop
and remember which comes first the counter or the contents. of course, its
still a lot better than the hideous old solution:
for i, v in zip(range(len(list), list):
removing the zip helps a bit (using my logic), and its clear which part goes
to which which var:
for i, v in range(len(list), list:
then if you had a function that returned the indexes of a list, its very
clear and only a couple of characters longer than enumerate, without the
order problem:
for i, v in indexes(list), list:
anyway its just something to think about, or maybe waste time thinking
about... ;) This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Markus Franz |
last post by:
Hi.
I have a difficult problem: An array contains several different URLs.
I want to load these websites in parallel by using a HTTP-Request. How
can I do this in PHP?
Up to now I did this...
|
by: Joshua Nussbaum |
last post by:
I came up with what I think is a good idea for making multithreading
programming easier in any .NET language. I dont know where else to post it,
so I'll try here.
..NET 2.0 adds the capability...
|
by: paytam |
last post by:
Hi all,
Is it possible to write parallel programming in C?
I mean for example a simple program like I have a clock on a program
that show me current time and and at the same time another job like...
|
by: ramyach |
last post by:
Hi friends,
I need to write a parallel code in 'C' on the server that is
running SGI Irix 6.5. This server supports MIPS Pro C compiler. I don't
have any idea of parallel C languages. I looked...
|
by: lovecreatesbeauty |
last post by:
For example, line L1 and line L2 are two lines in two-dimensional
space, the start-points and end-points can be described with following
the `point_t' type. The start-points and end-points are:...
|
by: Soren |
last post by:
Hi,
I want to control some motors using the parallel port.. however, my
laptop does not have any parallel ports (very few do). What I do have
is a USB->Parallel converter... I thought about...
|
by: Prime Mover |
last post by:
Hello all,
I have got the pseudo-code below that I would like to convert to c
language. The algorithm calculates Pi value. I am somewhat familiar
with C language, but I am just starting to learn...
|
by: John |
last post by:
I have a program that needs to run on a regular basis that looks at a
queue table in my database. If there are items in the queue database
I need to grab the data from the database and pass it to...
|
by: DJRhino |
last post by:
Was curious if anyone else was having this same issue or not....
I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM)
The start time is equivalent to 19:00 (7PM) in Central...
|
by: tracyyun |
last post by:
Hello everyone,
I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
|
by: NeoPa |
last post by:
Hello everyone.
I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report).
I know it can be done by selecting :...
|
by: NeoPa |
last post by:
Introduction
For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM)
Please note that the UK and Europe revert to winter time on...
|
by: nia12 |
last post by:
Hi there,
I am very new to Access so apologies if any of this is obvious/not clear.
I am creating a data collection tool for health care employees to complete. It consists of a number of...
|
by: NeoPa |
last post by:
Introduction
For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
|
by: GKJR |
last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...
| |