[issue24849] Add __len__ to map, everything in itertools

2015-08-12 Thread Steven D'Aprano
Steven D'Aprano added the comment: On Wed, Aug 12, 2015 at 09:23:26PM +, flying sheep wrote: Python has iterators and iterables. iterators are non-reentrant iterables: once they are exhausted, they are useless. Correct. But there are also iterables that create new, iterators whenever

[issue24849] Add __len__ to map, everything in itertools

2015-08-12 Thread Raymond Hettinger
Raymond Hettinger added the comment: I had explored this idea previously at some length (no pun intended) but it was mostly a dead-end. The best we ended-up with has having __length_hint__ to indicate size to list(). There were several issues some of which at detailed in the comment at

[issue24849] Add __len__ to map, everything in itertools

2015-08-12 Thread flying sheep
, and raise a TypeError if they are non-reentrant. (signified by “(r)→”) for the predicate functions, it’s questionable if we should offer it, since they might take a long time and “len” is a property-like function that feels like it should return fast. map(func, iterable) → len(iterable) count(), cycle

[issue24849] Add __len__ to map, everything in itertools

2015-08-12 Thread Steven D'Aprano
, it will be misleading and a bug magnet under certain circumstances. I don't believe it is worth giving iterators like map, zip etc. a length depending on the nature of what they are iterating over. That can only lead to confusion. Programmers just have to understand that sequences have lengths, but arbitrary

[issue24849] Add __len__ to map, everything in itertools

2015-08-12 Thread R. David Murray
R. David Murray added the comment: No, you may not iterate the iterator in order to compute the len, because then the iterator would be exhausted. In addition, the point of itertools is to *lazily* do operations on iterables of indefinite length, so to offer __len__ if and only if the

[issue24606] segfault caused by nested calls to map()

2015-07-10 Thread Ned Deily
Ned Deily added the comment: Process 51270 launched: './python' (x86_64) Process 51270 stopped * thread #1: tid = 0x5c8677, 0x0001000c1af8 python`_PyObject_Alloc(use_calloc=0, ctx=unavailable, nelem=unavailable, elsize=unavailable) + 24 at obmalloc.c:1170, queue = 'com.apple.main-thread',

[issue24606] segfault caused by nested calls to map()

2015-07-10 Thread Ned Deily
Changes by Ned Deily n...@acm.org: -- nosy: -ned.deily ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue24606 ___ ___ Python-bugs-list mailing list

[issue24606] segfault caused by nested calls to map()

2015-07-10 Thread Mark Lawrence
Mark Lawrence added the comment: FTR I can reproduce this on Windows 8.1 with 3.4.3 and 3.3.5 but not 2.7.10 or 2.6.6. -- nosy: +BreamoreBoy ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue24606

[issue24606] segfault caused by nested calls to map()

2015-07-10 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: This looks as a duplicate of issue14010. -- nosy: +serhiy.storchaka resolution: - duplicate stage: - resolved status: open - closed superseder: - deeply nested filter segfaults ___ Python tracker

[issue24606] segfault caused by nested calls to map()

2015-07-10 Thread David Lukeš
New submission from David Lukeš: The following program makes Python 3.4.3 crash with a segmentation fault: ``` #!/usr/bin/env python3 import operator N = 50 l = [0] for i in range(N): l = map(operator.add, l, [1]) print(list(l)) ``` I suppose the problem is that there are too many

[issue24446] imap and map inconsistent behaviour

2015-06-13 Thread Ned Deily
Ned Deily added the comment: This is a documented behavior difference in itertools.imap: If function is set to None, then imap() returns the arguments as a tuple. Like map() but stops when the shortest iterable is exhausted instead of filling in None for shorter iterables. The reason

[issue24446] imap and map inconsistent behaviour

2015-06-13 Thread Ned Deily
Ned Deily added the comment: Also note that the behavior of map() in Python 3 has been changed to also stop with the termination of the shortest iterator. https://docs.python.org/3.4/whatsnew/3.0.html#views-and-iterators-instead-of-lists

[issue24213] ProcessPoolExecutor().map() fails following an identical map()

2015-05-16 Thread Ned Deily
Ned Deily added the comment: I can reproduce a crash with your sample program using the current numpy wheel (1.9.2) and the python.org 3.4.3. The significant parts of the OS X crash dump: Crashed Thread:0 Dispatch queue: com.apple.main-thread Exception Type:EXC_BAD_ACCESS

[issue24213] ProcessPoolExecutor().map() fails following an identical map()

2015-05-16 Thread OceanEngineer
New submission from OceanEngineer: Attached file runs fine. Uncommenting line 19 makes python crash. Also, no crash happens if order of execution of map() and executor.map() is switched. This problem seems to be related to numpy in some way, the code does not crash if the commented return

[issue23697] Module level map submit for concurrent.futures

2015-03-18 Thread Ned Deily
Changes by Ned Deily n...@acm.org: -- nosy: +bquinlan ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue23697 ___ ___ Python-bugs-list mailing list

[issue23289] concurrent.futures.Executor.map is not equivalent to map.

2015-03-18 Thread Ned Deily
Changes by Ned Deily n...@acm.org: -- nosy: +bquinlan versions: -Python 3.2, Python 3.3, Python 3.4, Python 3.6 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue23289 ___

[issue23697] Module level map submit for concurrent.futures

2015-03-17 Thread Nick Coghlan
, perhaps based on the design of the event loop management interface in the asyncio module. -- messages: 238373 nosy: ncoghlan priority: normal severity: normal status: open title: Module level map submit for concurrent.futures ___ Python tracker rep

error of drawing map from shape file in Python 3.2 basemap

2015-02-14 Thread usact2012
I am working on drawing map from shape file in Python 3.2 basemap. But, the longitude values at the bottom axis are only shown partially. Also, all latitude values are missing. Here is my python code. import shapefile as sf import sys import numpy as np import matplotlib.pylab as plt from

[issue23289] concurrent.futures.Executor.map is not equivalent to map.

2015-01-21 Thread Piotr Majkrzak
New submission from Piotr Majkrzak: In documentation https://docs.python.org/3/library/concurrent.futures.html#concurrent.futures.Executor.map is writen that this fucntion is equivalent to the builtin map. But it is not true due to the fact that it is not lazy evalueded. The reason

Re: Help with map python 2

2015-01-05 Thread flebber
You could do what mathematicians do when they deal with alternating signs: they raise -1 to the power of the index to get an appropriate multiplier. [ n * (-1) ** n for n in range(10) ] [0, -1, 2, -3, 4, -5, 6, -7, 8, -9] Or you could do here what you attempt to do with map

Re: Help with map python 2

2015-01-05 Thread flebber
In py2, map produces a list already. In any case, above is syntax error without else clause. map(lambda x: x * -1 if x%2 else x, series) If you do not have a function already, a list comp is better. [(-1*k if k%2 else k) for k in range(2, N)] Change [] to () and you have

Re: Help with map python 2

2015-01-05 Thread Terry Reedy
to an arbitrarily large power. which could take an arbitrarily long time. Or you could do here what you attempt to do with map below. See below. You are trying to use a binary expression. There are no binary expressions. Add an else branch to make it ternary: lambda x : x if x % 2 == 0 else -x

Re: Help with map python 2

2015-01-05 Thread Steven D'Aprano
Terry Reedy wrote: On 1/5/2015 6:33 AM, flebber wrote: You could do what mathematicians do when they deal with alternating signs: they raise -1 to the power of the index to get an appropriate multiplier. [ n * (-1) ** n for n in range(10) ] [0, -1, 2, -3, 4, -5, 6, -7, 8, -9]

Help with map python 2

2015-01-04 Thread flebber
!= 0: answer.append(item * -1) else: answer.append(item) print(answer) I know I should be better off doing this with map but cannot get it to work. I understand also that map returns a generator so this solution should only working in python2(correct me please if I am wrong

Re: Help with map python 2

2015-01-04 Thread Chris Angelico
On Sun, Jan 4, 2015 at 10:34 PM, flebber flebber.c...@gmail.com wrote: Just getting something wrong list(map((lambda x: x * -1 if (x%2 != 0)), series)) Okay, and what happens when you run this? Do you get an exception? If so (and I fully expect you will), copy and paste the entire exception

Re: Help with map python 2

2015-01-04 Thread Alec Taylor
^To print the first 8. To print the first 100: map(lambda i: -i if i1==1 else i, xrange(2, 102)) On Sun, Jan 4, 2015 at 10:47 PM, Alec Taylor alec.tayl...@gmail.com wrote: map(lambda i: -i if i1==1 else i, xrange(2, 10)) On Sun, Jan 4, 2015 at 10:34 PM, flebber flebber.c...@gmail.com wrote

Re: Help with map python 2

2015-01-04 Thread Alec Taylor
map(lambda i: -i if i1==1 else i, xrange(2, 10)) On Sun, Jan 4, 2015 at 10:34 PM, flebber flebber.c...@gmail.com wrote: In repsonse to this question: Write a program that prints the first 100 members of the sequence 2, -3, 4, -5, 6, -7, 8. This is my solution it works but ugly. series

Re: Help with map python 2

2015-01-04 Thread Jussi Piitulainen
, 4, -5, 6, -7, 8, -9] Or you could do here what you attempt to do with map below. See below. # print(answer) answer = [] for item in series: if item % 2 != 0: answer.append(item * -1) else: answer.append(item) print(answer) I know I should be better off

Re: Help with map python 2

2015-01-04 Thread Peter Otten
in series: if item % 2 != 0: answer.append(item * -1) else: answer.append(item) print(answer) Hm, that's the only first 98 members. I know I should be better off doing this with map but cannot get it to work. I understand also that map returns a generator so

Re: Help with map python 2

2015-01-04 Thread Dan Stromberg
but ugly. series = range(2,100) # answer = [(x,(y* -1)) for x, y in series[::2]] # print(answer) answer = [] for item in series: if item % 2 != 0: answer.append(item * -1) else: answer.append(item) print(answer) I know I should be better off doing this with map

Re: Help with map python 2

2015-01-04 Thread Terry Reedy
this with map but cannot get it to work. I understand also that map returns a generator so this solution should only working in python2(correct me please if I am wrong). In [6]: map? Type: builtin_function_or_method String Form:built-in function map Namespace: Python builtin Docstring: map

Re: Help with map python 2

2015-01-04 Thread Sayth Renshaw
be better off doing this with map but cannot get it to work. I understand also that map returns a generator so this solution should only working in python2(correct me please if I am wrong). In [6]: map? Type: builtin_function_or_method String Form:built-in function map Namespace: Python

Re: Google Maps and Python: creating a map, embedding it, adding images, videos, markers, using python

2014-12-19 Thread Daniel da Silva
Kevin, that client library looks like it is for accessing Google Maps related services, not modifying maps themselves. On Fri, Dec 19, 2014 at 1:02 AM, Kev Dwyer kevin.p.dw...@gmail.com wrote: Veek M wrote: I'm messing with Google-Maps. Is there a way I can create a map, embed

Google Maps and Python: creating a map, embedding it, adding images, videos, markers, using python

2014-12-18 Thread Veek M
I'm messing with Google-Maps. Is there a way I can create a map, embed it on a page (CSS/HTML/Javascript for this bit), and add images, videos, markers - using python? Any libraries available? -- https://mail.python.org/mailman/listinfo/python-list

Re: Google Maps and Python: creating a map, embedding it, adding images, videos, markers, using python

2014-12-18 Thread Kev Dwyer
Veek M wrote: I'm messing with Google-Maps. Is there a way I can create a map, embed it on a page (CSS/HTML/Javascript for this bit), and add images, videos, markers - using python? Any libraries available? Hello, Googling for google maps python client returns https://developers.google.com

Re: Python Iterables struggling using map() built-in

2014-12-11 Thread Ian Kelly
On Wed, Dec 10, 2014 at 9:01 PM, Steven D'Aprano st...@pearwood.info wrote: On Wed, 10 Dec 2014 09:46:55 -0700, Ian Kelly wrote: I don't particularly have a problem with functions having attributes, e.g. I think itertools.chain.from_iterable is just peachy. There is a downside though,

Re: Python Iterables struggling using map() built-in

2014-12-11 Thread Steven D'Aprano
Ian Kelly wrote: A function, on the other hand, is not well suited to be a namespace, because it's not expected to provide one. And that is exactly the point I am making about the inherent conservativeness of Python developers. Functions ARE namespaces, like instances of user-defined

Re: Python Iterables struggling using map() built-in

2014-12-11 Thread Ian Kelly
On Thu, Dec 11, 2014 at 4:28 PM, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: Ian Kelly wrote: A function, on the other hand, is not well suited to be a namespace, because it's not expected to provide one. And that is exactly the point I am making about the inherent

Re: Python Iterables struggling using map() built-in

2014-12-11 Thread Chris Angelico
On Fri, Dec 12, 2014 at 10:28 AM, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: I think that there is a legitimate debate to be had as to whether this conservativeness and resistance to change is a good thing or a bad thing, but I don't think that there should be any debate about

Re: Python Iterables struggling using map() built-in

2014-12-11 Thread Roy Smith
In article mailman.16880.1418342293.18130.python-l...@python.org, Ian Kelly ian.g.ke...@gmail.com wrote: I never said that functions can't be used as namespaces. I said that functions are *bad* namespaces, and I gave reasons why I think this is true. An excellent example of functions acting

Re: Python Iterables struggling using map() built-in

2014-12-11 Thread Ian Kelly
On Thu, Dec 11, 2014 at 6:55 PM, Roy Smith r...@panix.com wrote: In article mailman.16880.1418342293.18130.python-l...@python.org, Ian Kelly ian.g.ke...@gmail.com wrote: I never said that functions can't be used as namespaces. I said that functions are *bad* namespaces, and I gave reasons

Re: Python Iterables struggling using map() built-in

2014-12-10 Thread Steven D'Aprano
On Tue, 09 Dec 2014 21:44:54 -0500, Roy Smith wrote: In article 54878f8a$0$13010$c3e8da3$54964...@news.astraweb.com, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: I really think you guys are trying too hard to make this function seem more complicated than it is. If you find

Re: Python Iterables struggling using map() built-in

2014-12-10 Thread Chris Angelico
On Wed, Dec 10, 2014 at 8:24 PM, Steven D'Aprano st...@pearwood.info wrote: And if anyone has got the impression that I'm calling you a dummy because you don't see it my way, I'm not. I'm calling you nekulturny and somebody who can't recognise elegant code when it's staring you right in the

Re: Python Iterables struggling using map() built-in

2014-12-10 Thread Marko Rauhamaa
Steven D'Aprano st...@pearwood.info: I've noticed this deep-seated conservatism in Python programmers before. Parts of the language are deeply under-utilised, because there are simple idioms that people refuse to use because they're confusing even though they are a trivial generalisation of

Re: Python Iterables struggling using map() built-in

2014-12-10 Thread Ian Kelly
On Wed, Dec 10, 2014 at 2:24 AM, Steven D'Aprano st...@pearwood.info wrote: Example: In the statistics module in Python 3.4, I added a `median` function to calculate the median by the traditional schoolbook algorithm. But that's only one out of a number of ways to calculate medium, and

Re: Python Iterables struggling using map() built-in

2014-12-10 Thread Terry Reedy
On 12/10/2014 11:46 AM, Ian Kelly wrote: I don't particularly have a problem with functions having attributes, e.g. I think itertools.chain.from_iterable is just peachy. There is a downside though, which is that making those functions attributes of another function rather than of the module

Re: Python Iterables struggling using map() built-in

2014-12-10 Thread Ian Kelly
On Wed, Dec 10, 2014 at 10:48 AM, Terry Reedy tjre...@udel.edu wrote: Likewise the generated help for the help() function, unless care is taken to explicitly mention the existence of those functions in either the doc string for the module help(it.chain) lists | from_iterable(...) from

Re: Python Iterables struggling using map() built-in

2014-12-10 Thread Steven D'Aprano
On Wed, 10 Dec 2014 09:46:55 -0700, Ian Kelly wrote: I don't particularly have a problem with functions having attributes, e.g. I think itertools.chain.from_iterable is just peachy. There is a downside though, which is that making those functions attributes of another function rather than of

Re: Python Iterables struggling using map() built-in

2014-12-10 Thread Terry Reedy
On 12/10/2014 3:32 PM, Ian Kelly wrote: So Idle gets it right. At least for static methods of classes, which isn't very surprising. Does it complete a function attribute of a function? def f(): pass f.a='attr' f. box with 'a' as possible completion. Having used Komodo IDE for a number

Re: Python Iterables struggling using map() built-in

2014-12-09 Thread Terry Reedy
On 12/9/2014 12:03 AM, Terry Reedy wrote: Roy Smith wrote: Chris Angelico wrote: def myzip(*args): iters = map(iter, args) while iters: res = [next(i) for i in iters] yield tuple(res) Ugh. When I see while foo, my brain says, OK, you're about to see a loop

Re: Python Iterables struggling using map() built-in

2014-12-09 Thread Steven D'Aprano
Terry Reedy wrote: On 12/9/2014 12:03 AM, Terry Reedy wrote: Roy Smith wrote: Chris Angelico wrote: def myzip(*args): iters = map(iter, args) while iters: res = [next(i) for i in iters] yield tuple(res) Ugh. When I see while foo, my brain says, OK, you're

Re: Python Iterables struggling using map() built-in

2014-12-09 Thread Chris Angelico
On Wed, Dec 10, 2014 at 11:10 AM, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: On the other hand, *premature optimization*. In general, one shouldn't write more complex code so the compiler can optimize it, one should write simpler code and have a smarter compiler. If *we* are

Re: Python Iterables struggling using map() built-in

2014-12-09 Thread Mark Lawrence
On 10/12/2014 00:10, Steven D'Aprano wrote: Wait... is this like the Four Yorkshire Men sketch from Monty Python, only instead of complaining about how hard you had it as children, you're all trying to outdo each other about how difficult you find it to read this function? If so, well done, you

Re: Python Iterables struggling using map() built-in

2014-12-09 Thread Roy Smith
In article 54878f8a$0$13010$c3e8da3$54964...@news.astraweb.com, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: I really think you guys are trying too hard to make this function seem more complicated than it is. If you find it so hard to understand a simple function with four

Re: Python Iterables struggling using map() built-in

2014-12-08 Thread Steven D'Aprano
On Mon, 08 Dec 2014 11:35:36 +1100, Chris Angelico wrote: On Mon, Dec 8, 2014 at 11:27 AM, Roy Smith r...@panix.com wrote: Although, to be honest, I'm wondering if this is more straight-forward (also not tested): def myzip37(*args): if not args: return iters = list(map

Re: Python Iterables struggling using map() built-in

2014-12-08 Thread Chris Angelico
On Mon, Dec 8, 2014 at 8:40 PM, Steven D'Aprano st...@pearwood.info wrote: The first version is explicit and clear too. I'm sorry to say this, but it is true: if you (generic you) don't recognise that while iters: ... skips the while block if iters is an empty list, then *you*

Re: Python Iterables struggling using map() built-in

2014-12-08 Thread Roy Smith
straight-forward (also not tested): def myzip37(*args): if not args: return iters = list(map(iter, args)) Yes, I prefer this too. It's explicit and clear that passing no arguments will yield no values. The first version is explicit and clear too. I'm sorry to say

Re: Python Iterables struggling using map() built-in

2014-12-08 Thread Steven D'Aprano
? :-) Here's the code again, with indentation fixed: def myzip(*args): iters = map(iter, args) while iters: res = [next(i) for i in iters] yield tuple(res) Ugh. When I see while foo, my brain says, OK, you're about to see a loop which is controlled by the value of foo

Re: Python Iterables struggling using map() built-in

2014-12-08 Thread Terry Reedy
On 12/8/2014 9:50 PM, Steven D'Aprano wrote: Roy Smith wrote: Chris Angelico wrote: def myzip(*args): iters = map(iter, args) while iters: res = [next(i) for i in iters] yield tuple(res) Ugh. When I see while foo, my brain says, OK, you're about to see a loop

Re: Python Iterables struggling using map() built-in

2014-12-08 Thread Steven D'Aprano
On Tue, 09 Dec 2014 00:03:33 -0500, Terry Reedy wrote: On 12/8/2014 9:50 PM, Steven D'Aprano wrote: Roy Smith wrote: Chris Angelico wrote: def myzip(*args): iters = map(iter, args) while iters: res = [next(i) for i in iters] yield tuple(res) Ugh. When I

Python Iterables struggling using map() built-in

2014-12-07 Thread Ivan Evstegneev
did some RTFM before posting. Links: 1. map() built-in definitions: https://docs.python.org/3/library/functions.html#map -for Python 3.X https://docs.python.org/2.6/library/functions.html#map - for Python 2.6.X 2. Glossary definitions of iterable and iterator: https

Re: Python Iterables struggling using map() built-in

2014-12-07 Thread Chris Angelico
this result: Traceback (most recent call last): File pyshell#73, line 1, in module next(k) File pyshell#65, line 2, in myzip iters = list(map(iter, args)) TypeError: 'int' object is not iterable We'll get back to this later. 1. L = [1, 2, 3, 4] iter(L) is L False

RE: Python Iterables struggling using map() built-in

2014-12-07 Thread Ivan Evstegneev
-list@python.org Subject: Re: Python Iterables struggling using map() built-in On 12/6/14 11:44 AM, Ivan Evstegneev wrote: And as I've promised the question section: 1.What actually map() trying to do in Python 3.X? I mean, why is this works fine: L = [1, 2, 3, 4] k = iter(L) next(k) 1

Re: Python Iterables struggling using map() built-in

2014-12-07 Thread Chris Angelico
; in Py3, iters will indeed never be false, unless you use list() to coalesce the map). This is something which definitely ought to have been given a comment. Or, more usefully, a guarding 'if' before the loop, rather than needlessly checking at every iteration - if you want an infinite loop guarded

Re: Python Iterables struggling using map() built-in

2014-12-07 Thread Ian Kelly
On Dec 7, 2014 8:31 AM, Ned Batchelder n...@nedbatchelder.com wrote: NOTE: THIS EXAMPLE IS HORRIBLE. This code is crazy-confusing, and should never have been used as an example of iteration. It layers at least three iterations on top of each other, making it very difficult to see what is going

Re: Python Iterables struggling using map() built-in

2014-12-07 Thread Chris Angelico
On Mon, Dec 8, 2014 at 5:27 AM, Ian Kelly ian.g.ke...@gmail.com wrote: On Dec 7, 2014 8:31 AM, Ned Batchelder n...@nedbatchelder.com wrote: NOTE: THIS EXAMPLE IS HORRIBLE. This code is crazy-confusing, and should never have been used as an example of iteration. It layers at least three

Re: Python Iterables struggling using map() built-in

2014-12-07 Thread Steven D'Aprano
will break this kind of code. Gives a good excuse for rewriting it to be more readable. What kind of code is that? Short, simple, Pythonic and elegant? :-) Here's the code again, with indentation fixed: def myzip(*args): iters = map(iter, args) while iters: res = [next(i) for i in iters

Re: Python Iterables struggling using map() built-in

2014-12-07 Thread Chris Angelico
On Mon, Dec 8, 2014 at 10:33 AM, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: How would we re-write this to work in the future Python 3.7? Unless I have missed something, I think we could write it like this: def myzip37(*args): iters = list(map(iter, args)) while iters

Re: Python Iterables struggling using map() built-in

2014-12-07 Thread Roy Smith
, with indentation fixed: def myzip(*args): iters = map(iter, args) while iters: res = [next(i) for i in iters] yield tuple(res) Ugh. When I see while foo, my brain says, OK, you're about to see a loop which is controlled by the value of foo being changed inside

Re: Python Iterables struggling using map() built-in

2014-12-07 Thread Roy Smith
, I think we could write it like this: def myzip37(*args): iters = list(map(iter, args)) while iters: try: yield tuple([next(i) for i in iters]) except StopIteration: return I'm still not liking this use of while. Yes, of course

Re: Python Iterables struggling using map() built-in

2014-12-07 Thread Chris Angelico
On Mon, Dec 8, 2014 at 11:12 AM, Roy Smith r...@panix.com wrote: Ugh. When I see while foo, my brain says, OK, you're about to see a loop which is controlled by the value of foo being changed inside the loop. That's not at all what's happening here, so my brain runs into a wall. I agree,

Re: Python Iterables struggling using map() built-in

2014-12-07 Thread Chris Angelico
On Mon, Dec 8, 2014 at 11:27 AM, Roy Smith r...@panix.com wrote: Although, to be honest, I'm wondering if this is more straight-forward (also not tested): def myzip37(*args): if not args: return iters = list(map(iter, args)) Yes, I prefer this too. It's explicit and clear

Re: Python Iterables struggling using map() built-in

2014-12-07 Thread Terry Reedy
and elegant? :-) Here's the code again, with indentation fixed: def myzip(*args): iters = map(iter, args) while iters: res = [next(i) for i in iters] yield tuple(res) Ugh. When I see while foo, my brain says, OK, you're about to see a loop which is controlled by the value

Re: Python Iterables struggling using map() built-in

2014-12-07 Thread Roy Smith
In article mailman.16690.1417998873.18130.python-l...@python.org, Chris Angelico ros...@gmail.com wrote: Next problem, what the heck is res? We're not back in the punch-card days. We don't have to abbreviate variable names to save columns. Variable names are supposed to describe what

Re: Python Iterables struggling using map() built-in

2014-12-07 Thread Chris Angelico
On Mon, Dec 8, 2014 at 11:45 AM, Roy Smith r...@panix.com wrote: I take it as result, which makes plenty of sense to me. OK, so spell it out. Three more keystrokes (well, plus another three when you use it on the next line). And one of them is a vowel; they don't even cost much. The next

Re: Python Iterables struggling using map() built-in

2014-12-07 Thread Ned Batchelder
and elegant? :-) Here's the code again, with indentation fixed: def myzip(*args): iters = map(iter, args) while iters: res = [next(i) for i in iters] yield tuple(res) Ugh. When I see while foo, my brain says, OK, you're about to see a loop which is controlled by the value

Re: Python Iterables struggling using map() built-in

2014-12-07 Thread MRAB
On 2014-12-08 01:00, Chris Angelico wrote: On Mon, Dec 8, 2014 at 11:45 AM, Roy Smith r...@panix.com wrote: I take it as result, which makes plenty of sense to me. OK, so spell it out. Three more keystrokes (well, plus another three when you use it on the next line). And one of them is a

Re: Python Iterables struggling using map() built-in

2014-12-07 Thread Gregory Ewing
Steven D'Aprano wrote: I do not believe that good code must be obviously right. It's okay for code to be subtly right. If you write code as subtly as you can, you're not subtle enough to debug it... -- Greg -- https://mail.python.org/mailman/listinfo/python-list

Re: Python Iterables struggling using map() built-in

2014-12-07 Thread Gregory Ewing
Terry Reedy wrote: However, this 'beautiful' code has a trap. If one gets rid of the seemingly unneeded temporary list res by telescoping the last two lines into a bit too much into yield tuple(next(i) for i in iters) we now have an infinite generator, because tuple() swallows

Using map()

2014-11-16 Thread Pavel Volkov
I checked my modules with pylint and saw the following warning: W: 25,29: Used builtin function 'map' (bad-builtin) Why is the use of map() discouraged? It' such a useful thing. -- https://mail.python.org/mailman/listinfo/python-list

Re: Using map()

2014-11-16 Thread Joel Goldstick
On Sun, Nov 16, 2014 at 8:01 AM, Pavel Volkov sai...@lists.xtsubasa.org wrote: I checked my modules with pylint and saw the following warning: W: 25,29: Used builtin function 'map' (bad-builtin) Why is the use of map() discouraged? It' such a useful thing. -- https://mail.python.org

RE: Using map()

2014-11-16 Thread Joseph L. Casale
I checked my modules with pylint and saw the following warning: W: 25,29: Used builtin function 'map' (bad-builtin) Why is the use of map() discouraged? It' such a useful thing. The warning manifests from the opinion that a comprehension is more suitable. You can disable the warning or you

Re: Using map()

2014-11-16 Thread Terry Reedy
On 11/16/2014 8:01 AM, Pavel Volkov wrote: I checked my modules with pylint and saw the following warning: W: 25,29: Used builtin function 'map' (bad-builtin) Why is the use of map() discouraged? It' such a useful thing. I consider that to be a bug in pylint. It misstates a careless 'bad

Re: Using map()

2014-11-16 Thread Steven D'Aprano
Pavel Volkov wrote: I checked my modules with pylint and saw the following warning: W: 25,29: Used builtin function 'map' (bad-builtin) Why is the use of map() discouraged? It' such a useful thing. That's a bug in pylint. It's not a bad builtin, it is perfectly fine. Some people don't

Re: Using map()

2014-11-16 Thread Ned Batchelder
On 11/16/14 7:09 PM, Steven D'Aprano wrote: Pavel Volkov wrote: I checked my modules with pylint and saw the following warning: W: 25,29: Used builtin function 'map' (bad-builtin) Why is the use of map() discouraged? It' such a useful thing. That's a bug in pylint. It's not a bad builtin

Re: Using map()

2014-11-16 Thread Chris Angelico
On Mon, Nov 17, 2014 at 11:24 AM, Ned Batchelder n...@nedbatchelder.com wrote: Pylint isn't useful until you've tailored the messages. Personally, I avoid map, but your usage may vary. The pylint message that always irked me was: W0142: Used * or ** magic This is why I don't bother

Messages from code analysis tools (was: Using map())

2014-11-16 Thread Ben Finney
Ned Batchelder n...@nedbatchelder.com writes: Pylint isn't useful until you've tailored the messages. Definitely agreed. The pylint message that always irked me was: W0142: Used * or ** magic magic? They're features of the language! It's a warning, because the use of that feature

Re: Using map()

2014-11-16 Thread Dan Stromberg
On Sun, Nov 16, 2014 at 4:09 PM, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: Pavel Volkov wrote: I checked my modules with pylint and saw the following warning: W: 25,29: Used builtin function 'map' (bad-builtin) Why is the use of map() discouraged? It' such a useful thing

Re: Messages from code analysis tools (was: Using map())

2014-11-16 Thread Chris Angelico
On Mon, Nov 17, 2014 at 12:21 PM, Ben Finney ben+pyt...@benfinney.id.au wrote: The pylint message that always irked me was: W0142: Used * or ** magic magic? They're features of the language! It's a warning, because the use of that feature clobbers the static code inspection you've

Re: Using map()

2014-11-16 Thread Ian Kelly
On Sun, Nov 16, 2014 at 4:22 PM, Terry Reedy tjre...@udel.edu wrote: If pylint sees 'map(lambda ...: ', it would be appropriate to suggest using a comprehension or generator expression instead. This avoids the unneeded creation and repeated call of a new function. There's actually a separate

2d color-bar map plot

2014-10-17 Thread Dhananjay
,z axis data points. This is not a continuous data. I wish to make a plot as a 2D with 3rd dimension (i.e z-axis data) as a color map with color bar on right hand side. As a beginner, I tried to follow tutorial with some modification as follows: http://matplotlib.org/examples/pylab_examples

Re: 2d color-bar map plot

2014-10-17 Thread Peter Pearson
On Fri, 17 Oct 2014 14:28:13 +0800, Dhananjay wrote: [snip] xs = ys = zs = [] for line in fl1: line = line.split() xs.append(float(line[0])) ys.append(float(line[1])) zs.append(float(line[2])) print xs[0], ys[0], zs[0] The line xs = ys = zs = [] is almost surely not what

Re: 2d color-bar map plot

2014-10-17 Thread Mark Lawrence
On 17/10/2014 07:28, Dhananjay wrote: Dear all, I am bit new to the python/pyplot. This might be simple, but I guess I am missing something here. I doubt that you'll get detailed answers here so suggest you try https://lists.sourceforge.net/lists/listinfo/matplotlib-users which is also

[issue22294] 2to3 consuming_calls: len, min, max, zip, map, reduce, filter, dict, xrange

2014-10-07 Thread Edward O
Changes by Edward O edoubray...@gmail.com: -- nosy: +BreamoreBoy ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue22294 ___ ___ Python-bugs-list

[issue22294] 2to3 consuming_calls: len, min, max, zip, map, reduce, filter, dict, xrange

2014-08-29 Thread Terry J. Reedy
Changes by Terry J. Reedy tjre...@udel.edu: -- versions: -Python 3.1, Python 3.2, Python 3.3 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue22294 ___

[issue22294] 2to3 consuming_calls: len, min, max, zip, map, reduce, filter, dict, xrange

2014-08-28 Thread Edward O
New submission from Edward O: This is a patch for issues similar to #16573 With this patch, the following new tests are now unchanged: r = dict(zip(s, range(len(s))), **d) r = len(filter(attrgetter('t'), self.a)) r = min(map(methodcaller('f'), self.a)) max(map(node.id, self.nodes)) + 1

[issue22294] 2to3 consuming_calls: len, min, max, zip, map, reduce, filter, dict, xrange

2014-08-28 Thread Edward O
Changes by Edward O edoubray...@gmail.com: -- nosy: +benjamin.peterson ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue22294 ___ ___

Re: How to draw a map using python

2014-08-10 Thread Ian Kelly
On Sat, Aug 9, 2014 at 7:44 PM, Yuanchao Xu xuyuancha...@gmail.com wrote: 1. I wonder in python, is there any more fast way to generate this kind of map, as a whole, not a series of shapes, i think that would be faster?? You mean like collecting all the shapes into a single sparse array

Re: Fwd: How to draw a map using python

2014-08-10 Thread Mark Lawrence
On 10/08/2014 02:44, Yuanchao Xu wrote: To kind whom it may concern: I want to draw a map using python, not really a map with full information, just a get together of a series of small shapes to reflect land use. The data is like below |1 2 2 3 3 2 2 3 3 1 1 2 1 1 1 1 3 3 3 3

[issue22180] operator.setitem example no longer works in Python 3 due to lazy map

2014-08-10 Thread Michael Williamson
New submission from Michael Williamson: The Python docs for the operator module include an example using map and setitem to Build a dictionary that maps the ordinals from 0 to 255 to their character equivalents.: d = {} keys = range(256) vals = map(chr, keys) map

<    1   2   3   4   5   6   7   8   9   10   >