is there a concurrent list for append in parallel programming in python? how to pass parameter in this parallel program with pool?

Steven D'Aprano steve+comp.lang.python at pearwood.info
Thu Jun 16 04:30:10 EDT 2016


On Thursday 16 June 2016 17:28, meInvent bbird wrote:

> is there like c# have concurrent list ?

What is a concurrent list?

Can you link to the C# documentation for this?

To me, "concurrent" describes a style of execution flow, and "list" describes a 
data structure. I am struggling to understand what "concurrent list" means.

> i find something these, but how can it pass an initlist list variable

initlist = ['a', 'b', 'c']
result = comb(n, initlist)  # pass initlist


> is it doing the same function as itertools.combinations ?

It is calling itertools.combinations. So, yes, it is doing the same function as 
itertools.combinations.


> def comb(n, initlist): # the argument n is the number of items to select
>     res = list(itertools.combinations(initlist, n)) # create a list from the
>                                                     # iterator 
>     return res

This does not generate the combinations in parallel. It generates them one at a 
time, and then creates a list of them.

This is an interesting question. Somebody could probably write a parallel 
version of combinations. But I don't know that it would be very useful -- the 
limiting factor on combinations is more likely to be memory, not time.

Suppose you generate combinations of 100 items, taken 10 at a time. If I 
remember the formula for combinations correctly, the total number of 
combinations is:

100!/(10! * 90!) = 17310309456440

combinations in total. If each generated combination took just *one* byte of 
memory, that would require over 17 TB of RAM.



-- 
Steve



More information about the Python-list mailing list