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 3413
>>>> 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_wi th(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_wi th(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(l ist), 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 with an external Python script because Python
offers process control functions. But in PHP only exist restricted
possibilities for using threads / processes.
|
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 to write anonymous functions, it would be nice
if there was a "parallel" statement, that could simplify writing threadprocs.
e.g. (theoretical c#)
public void DoSomeParallelStuff() {
|
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
input data from a user.If it is possible PLZ write a simple code for me
..
|
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 into few posts in this
group. I could make out that there are several languages for parallel
programming and parallel C is one of them. I need to know if this is
supported by MIPS Pro C Compiler. Or are there any other parallel C
languages that have...
|
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: Line L1
(L1_str, L1_end), L2 (L2_str, L2_end).
Can I compare the float value of sloping rate of two lines to determine
whether they are parallel lines? Some paper books tell that float value
can not be compared to float value. Some people also try...
| |
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 using PyParallel, but
the USB->Parallel converter doesn't actually map to the LPT port ..
and PyParallel only looks for LPT ports?
Has anyone tried doing this? What are my options for controlling
parallel connections on a laptop with no parallel...
|
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 parallel programming.
In this specific example, the idea seems to be simple: one must
subdivide the main loop into pieces that can be executed by
independent "tasks" (computers??).
Then, each "worker task" executes a part of the loop a...
|
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 a web service
to process. The web service will return either a completion code or
error msg (the only errors expected would be timeout or cannot
connection errors). This queue file can contain 0 to N messages.
Naturally if there are no messages...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |