Re: Differences creating tuples and collections.namedtuples

2013-02-18 Thread raymond . hettinger
On Monday, February 18, 2013 6:09:16 AM UTC-8, John Reid wrote: > I'm aware how to construct the namedtuple and the tuple. My point was > that they use different syntaxes for the same operation and this seems > to break ipython. I was wondering if this is a necessary design feature > or perhaps jus

Re: Python education survey

2011-12-22 Thread Raymond Hettinger
On Dec 21, 9:57 am, Nathan Rice wrote: > +1 for IPython/%edit using the simplest editor that supports syntax > highlighting and line numbers.  I have found that > Exploring/Prototyping in the interpreter has the highest ROI of > anything I teach people. Thank you Nathan and all the other responde

Python education survey

2011-12-19 Thread Raymond Hettinger
Do you use IDLE when teaching Python? If not, what is the tool of choice? Students may not be experienced with the command-line and may be running Windows, Linux, or Macs. Ideally, the tool or IDE will be easy to install and configure (startup directory, path, associated with a particular version

Re: list(), tuple() should not place at "Built-in functions" in documentation

2011-07-19 Thread Raymond Hettinger
On Jul 14, 6:21 pm, Inside wrote: > As telling in the subject,because "list" and "tuple" aren't functions,they > are types.Is that right? list() and tuple() are in the right place in the documentation because they would be harder to find if listed elsewhere. Tools like str(), int(), list(), tu

Re: a little parsing challenge ☺

2011-07-17 Thread Raymond Hettinger
On Jul 17, 8:49 am, Thomas Boell wrote: > But why do you enumerate with start=1? Shouldn't you start with index 0? The problem specification says that the the char number should match the emacs goto-char function which is indexed from one, not from zero. This is testable by taking the output of

Re: a little parsing challenge ☺

2011-07-17 Thread Raymond Hettinger
On Jul 17, 7:15 am, Thomas 'PointedEars' Lahn wrote: > Did you notice the excessive crosspost?  Please do not feed the troll. IMO, this was a legitimate cross post since it is for a multi-language programming challenge and everyone can learn from comparing the results. Raymond -- http://mail.p

Re: a little parsing challenge ☺

2011-07-17 Thread Raymond Hettinger
On Jul 17, 12:47 am, Xah Lee wrote: > i hope you'll participate. Just post solution here. Thanks. http://pastebin.com/7hU20NNL Raymond -- http://mail.python.org/mailman/listinfo/python-list

Re: blist question

2011-07-07 Thread Raymond Hettinger
On Jul 7, 5:08 am, dmitrey wrote: > hi all, > I feel lack of native Python lists operations (e.g. taking N greatest > elements with the involved key function and O(n) speed) Take a look at heapq.nlargest()... > and > occasionally found blisthttp://pypi.python.org/pypi/blist/ > Its entry says it

Re: Dictionaries and incrementing keys

2011-06-25 Thread Raymond Hettinger
On Jun 14, 12:57 pm, Steve Crook wrote: > Today I spotted an alternative: > > dict[key] = dict.get(key, 0) + 1 > > Whilst certainly more compact, I'd be interested in views on how > pythonesque this method is. It is very pythonesque in the it was the traditional one way to do it (also one of the

Re: Is there any advantage or disadvantage to using sets over list comps to ensure a list of unique entries?

2011-06-25 Thread Raymond Hettinger
On Jun 20, 9:43 pm, deathweaselx86 wrote: > Howdy guys, I am new. > > I've been converting lists to sets, then back to lists again to get > unique lists. > e.g > > Python 2.5.2 (r252:60911, Jan 20 2010, 21:48:48) > [GCC 4.2.4 (Ubuntu 4.2.4-1ubuntu3)] on linux2 > Type "help", "copyright", "credits"

Re: Bloom Filter in 22 lines of Python (updated)

2011-06-08 Thread Raymond Hettinger
On Jun 6, 10:47 am, geremy condra wrote: > On Fri, Jun 3, 2011 at 1:17 PM, Raymond Hettinger wrote: > > Thanks for all the feedback on the earlier post. > > > I've updated the recipe to use a cleaner API, simpler code, > > more easily subclassable, and with optional

Bloom Filter in 22 lines of Python (updated)

2011-06-03 Thread Raymond Hettinger
Thanks for all the feedback on the earlier post. I've updated the recipe to use a cleaner API, simpler code, more easily subclassable, and with optional optimizations for better cache utilization and speed: http://code.activestate.com/recipes/577684-bloom-filter/ Raymond -

Re: Standard Deviation One-liner

2011-06-03 Thread Raymond Hettinger
On Jun 3, 10:55 am, Billy Mays wrote: > I'm trying to shorten a one-liner I have for calculating the standard > deviation of a list of numbers.  I have something so far, but I was > wondering if it could be made any shorter (without imports). > > Here's my function: > > a=lambda d:(sum((x-1.*sum(d

Updated blog post on how to use super()

2011-05-31 Thread Raymond Hettinger
goal is to serve as a reliable guide to using super and how to design cooperative classes in a way that lets subclasses compose and extent them. Raymond Hettinger follow my python tips on twitter: @raymondh -- http://mail.python.org/mailman/listinfo/python-list

Re: 3.1.4 release candidate 1

2011-05-29 Thread Raymond Hettinger
On May 29, 3:44 pm, Benjamin Peterson wrote: > On behalf of the Python development team, I'm happy as a swallow to announce a > release candidate for the fourth bugfix release for the Python 3.1 > series, Python > 3.1.4. The Pi release of Python :-) Raymond P.S. For the most part, if you have

Re: float("nan") in set or as key

2011-05-29 Thread Raymond Hettinger
On May 28, 4:41 pm, MRAB wrote: > Here's a curiosity. float("nan") can occur multiple times in a set or as > a key in a dict: Which is by design. NaNs intentionally have multiple possible instances (some implementations even include distinct payload values). Sets and dicts intentionally recogni

Re: Class decorators might also be super too

2011-05-29 Thread Raymond Hettinger
On May 28, 11:33 pm, Michele Simionato wrote: > He is basically showing that using mixins for implementing logging is not > such a good idea, i.e. you can get the same effect in a better way by making > use of other Python features. I argued the same thing many times in the past. > I even wrote

Class decorators might also be super too

2011-05-28 Thread Raymond Hettinger
David Beazley wrote a class decorator blog post that is worth reading: http://dabeaz.blogspot.com/2011/05/class-decorators-might-also-be-super.html Raymond -- http://mail.python.org/mailman/listinfo/python-list

Re: Python's super() considered super!

2011-05-27 Thread Raymond Hettinger
On May 26, 6:39 pm, Ben Finney wrote: > We also, though, need *real* URLs. Blind URLs through obfuscation > services have their uses, but surely not in a forum like this. The real > URL is http://news.ycombinator.com/item?id=2588262>. Fair enough. I had copied the link from Jesse's tweet (where

Re: Python's super() considered super!

2011-05-26 Thread Raymond Hettinger
> It would also be great if some of you would upvote it on HackerNews. Here's a link to the super() how-to-guide and commentary: bit.ly/ iFm8g3 Raymod -- http://mail.python.org/mailman/listinfo/python-list

Python's super() considered super!

2011-05-26 Thread Raymond Hettinger
uper-considered-super/ It would also be great if some of you would upvote it on HackerNews. Raymond Hettinger --- follow my python tips on twitter: @raymondh -- http://mail.python.org/mailman/listinfo/python-list

Re: Parse config file and command-line arguments, to get a single collection of options

2011-05-25 Thread Raymond Hettinger
On May 25, 9:38 pm, Ben Finney wrote: > Howdy all, > > Python's standard library has modules for configuration file parsing > (configparser) and command-line argument parsing (optparse, argparse). I > want to write a program that does both, but also: > > * Has a cascade of options: default option

Re: super() in class defs?

2011-05-25 Thread Raymond Hettinger
r Python toolkit. If any of the comp.lang.python readers want to review and comment on my latest draft, please email me and I'll send it to you directly. Cheers, Raymond Hettinger my email address is listed at http://users.rcn.com/python/download/Descriptor.htm -- http://mail.pytho

Re: Faster Recursive Fibonacci Numbers

2011-05-24 Thread Raymond Hettinger
On May 17, 8:50 am, RJB wrote: > I noticed some discussion of recursion. the trick is to find a > formula where the arguments are divided, not decremented. > I've had a "divide-and-conquer" recursion for the Fibonacci numbers > for a couple of years in C++ but just for fun rewrote it > in Pyth

Re: Python 3 dict question

2011-05-10 Thread Raymond Hettinger
On May 6, 12:40 pm, dmitrey wrote: > hi all, > suppose I have Python dict myDict and I know it's not empty. > I have to get any (key, value) pair from the dict (no matter which > one) and perform some operation. > In Python 2 I used mere > key, val = myDict.items()[0] > but in Python 3 myDict.item

Re: string formatting

2011-05-10 Thread Raymond Hettinger
> Which is the preferred way of string formatting? > > (1) "the %s is %s" % ('sky', 'blue') > > (2) "the {0} is {1}".format('sky', 'blue') > > (3) "the {} is {}".format('sky', 'blue') > > As I know (1) is old style. (2) and (3) are new but (3) is only > supported from Python 2.7+. > > Which one sho

Re: Coolest Python recipe of all time

2011-05-09 Thread Raymond Hettinger
On May 9, 2:31 am, Trent Nelson wrote: > > What are your favorites? > > I think I've posted this before, but I love my > 3-lines-if-you-ignore-the-scaffolding language translator.  Not because it's > clever code -- quite the opposite, the code is dead simple -- but because it > encompasses one

Re: Coolest Python recipe of all time

2011-05-07 Thread Raymond Hettinger
On May 7, 1:29 am, Steven D'Aprano wrote: > On Fri, 06 May 2011 12:36:09 -0600, Ian Kelly wrote: > > The amb engine would conceptually execute this function for every > > possible combination of a, b, and c, > > Which pretty much is the definition of "brute-force solver", no? FWIW, here's one of

Re: checking if a list is empty

2011-05-06 Thread Raymond Hettinger
On May 5, 11:36 pm, Jabba Laci wrote: > Hi, > > If I want to check if a list is empty, which is the more pythonic way? > > li = [] > > (1) if len(li) == 0: > ... > or > (2) if not li: The Python core developers use the second form. See http://www.python.org/dev/peps/pep-0008/ for the official rec

Re: Coolest Python recipe of all time

2011-05-06 Thread Raymond Hettinger
[Steven D'Aprano]: > As written, amb is just a brute-force solver using more magic than is > good for any code, but it's fun to play with. With a small change in API, much of the magic isn't needed. from itertools import product def amb(func, *argument_ranges): for args in product(*argument_

Re: Today's fun and educational Python recipe

2011-05-04 Thread Raymond Hettinger
On May 4, 5:26 pm, Terry Reedy wrote: > The test would be more convincing to many with 10 other geographic > names (hard to come by, I know), or other english names or words or even > with longer random strings that matched the lengths of the state names. > But an average of 5/10 false pos

Re: Today's fun and educational Python recipe

2011-05-04 Thread Raymond Hettinger
On May 4, 12:27 pm, Paul Rubin wrote: > Raymond Hettinger writes: > > Here's a 22-line beauty for a classic and amazing algorithm: > >http://bit.ly/bloom_filter > > The use of pickle to serialize the keys is a little bit suspicious if > there might be a reason to d

Re: Today's fun and educational Python recipe

2011-05-04 Thread Raymond Hettinger
On May 4, 12:42 pm, Terry Reedy wrote: > On 5/4/2011 2:17 PM, Raymond Hettinger wrote: > > > Here's a 22-line beauty for a classic and amazing algorithm: > >http://bit.ly/bloom_filter > > > The wiki article on the algorithm is brief and well-written: > >htt

Re: Today's fun and educational Python recipe

2011-05-04 Thread Raymond Hettinger
> > It turns out that people in the 1970's were pretty smart :-) > > I think that often, the cleverness of people is inversely proportional > to the amount of CPU power and RAM that they have in their computer. The Google guys have plenty of CPU power *and* plenty of cleverness :-) According to t

Today's fun and educational Python recipe

2011-05-04 Thread Raymond Hettinger
Here's a 22-line beauty for a classic and amazing algorithm: http://bit.ly/bloom_filter The wiki article on the algorithm is brief and well-written: http://en.wikipedia.org/wiki/Bloom_filter It turns out that people in the 1970's were pretty smart :-) Raymond --- follow my other python tip

Re: Coolest Python recipe of all time

2011-05-03 Thread Raymond Hettinger
On May 2, 11:23 pm, Stefan Behnel wrote: > Terry Reedy, 03.05.2011 08:00: > > > On 5/3/2011 1:04 AM, Stefan Behnel wrote: > > >> The bad thing about this recipe is that it requires quite a bit of > >> background knowledge in order to infer that the code the developer is > >> looking at is actually

Re: Coolest Python recipe of all time

2011-05-03 Thread Raymond Hettinger
On May 2, 10:04 pm, Stefan Behnel wrote: > The bad thing about this recipe is that it requires quite a bit of > background knowledge in order to infer that the code the developer is > looking at is actually correct. At first sight, it looks like an evil hack, > and the lack of documentation doesn'

Re: Coolest Python recipe of all time

2011-05-03 Thread Raymond Hettinger
On May 2, 11:29 pm, Gregory Ewing wrote: > Terry Reedy wrote: > > The trick is that replacing x with j and evaluating > > therefore causes (in Python) all the coefficients of x (now j) to be > > added together separately from all the constant terms to reduce the > > linear equation to a*x+b (= 0 i

Coolest Python recipe of all time

2011-05-02 Thread Raymond Hettinger
I think it is time to give some visibility to some of the instructive and very cool recipes in ActiveState's python cookbook. My vote for the coolest recipe of all time is: http://code.activestate.com/recipes/365013-linear-equations-solver-in-3-lines/ What are your favorites? Raymond twit

Re: Have you read the Python docs lately?

2011-04-28 Thread Raymond Hettinger
On Apr 27, 11:28 pm, Paul Rubin wrote: > Raymond Hettinger writes: > > A number of developers have been working on adding examples and useful > > advice to the docs.  To sharpen your skills, here are some pieces of > > recommended reading: > > Thanks, those are n

Have you read the Python docs lately?

2011-04-27 Thread Raymond Hettinger
A number of developers have been working on adding examples and useful advice to the docs. To sharpen your skills, here are some pieces of recommended reading: http://docs.python.org/dev/library/heapq.html#priority-queue-implementation-notes http://docs.python.org/dev/library/bisect.html#searchi

Re: De-tupleizing a list

2011-04-26 Thread Raymond Hettinger
On Apr 25, 8:28 pm, Gnarlodious wrote: > I have an SQLite query that returns a list of tuples: > > [('0A',), ('1B',), ('2C',), ('3D',),... > > What is the most Pythonic way to loop through the list returning a > list like this?: > > ['0A', '1B', '2C', '3D',... You could unpack the 1-tuple the sam

Re: Case study: debugging failed assertRaises bug

2011-04-26 Thread Raymond Hettinger
On Apr 25, 11:05 pm, Steven D'Aprano wrote: > I've just spent two hours banging my head against what I *thought* > (wrongly!) was a spooky action-at-a-distance bug in unittest, so I > thought I'd share it with anyone reading. Thanks for telling your story. I'm sure the lessons learned will be hel

Re: Simple map/reduce utility function for data analysis

2011-04-26 Thread Raymond Hettinger
On Apr 25, 7:42 pm, Paul Rubin wrote: > Raymond Hettinger writes: > > Here's a handy utility function for you guys to play with: > >    http://code.activestate.com/recipes/577676/ > > Cute, but why not use collections.defaultdict for the return dict? > Untested: My

Simple map/reduce utility function for data analysis

2011-04-25 Thread Raymond Hettinger
Here's a handy utility function for you guys to play with: http://code.activestate.com/recipes/577676/ Raymond twitter: @raymondh -- http://mail.python.org/mailman/listinfo/python-list

Re: suggestions, comments on an "is_subdict" test

2011-04-23 Thread Raymond Hettinger
On Apr 22, 8:18 am, MRAB wrote: > On 22/04/2011 15:57, Irmen de Jong wrote: > > > > > > > > > On 22-4-2011 15:55, Vlastimil Brom wrote: > >> Hi all, > >> I'd like to ask for comments or advice on a simple code for testing a > >> "subdict", i.e. check whether all items of a given dictionary are > >

Re: Equivalent code to the bool() built-in function

2011-04-18 Thread Raymond Hettinger
On Apr 16, 1:24 pm, candide wrote: > Consider the following code : > > # -- > def bool_equivalent(x): >      return True if x else False It's faster to write: def bool_equivalent(x): return not not x Raymond -- http://mail.python.org/mailman/listinfo/py

Re: Questions about GIL and web services from a n00b

2011-04-15 Thread Raymond Hettinger
> > Is the limiting factor CPU? > > > If it isn't (i.e. you're blocking on IO to/from a web service) then the > > GIL won't get in your way. > > > If it is, then run as many parallel *processes* as you have cores/CPUs > > (assuming you're designing an application that can have multiple > > instance

Re: dict.setdefault()

2011-04-11 Thread Raymond Hettinger
On Apr 11, 4:25 pm, Tim Chase wrote: > Finally, if it were added, I'd call it something like merge() Guido rejected merge() a long time ago. Anyway, there is a new ChainMap() tool in the collections module for Py3.3 that should address a number of use cases for handling default values. Raymond

Re: dict.setdefault()

2011-04-11 Thread Raymond Hettinger
On Apr 11, 2:35 pm, rantingrick wrote: > setdefault should take **kw args in the case of needing to set > multiple defaults at one time. I would even settle for an *arg list if > i had to. Anything is better than... > > d.setdefault(blah, blah) > d.setdefault(blah, blah) > d.setdefault(blah, blah)

Re: python on iPad (PyPad)

2011-04-09 Thread Raymond Hettinger
On Apr 8, 10:13 pm, Jon Dowdall wrote: > Hi All, > > Sorry for the blatant advertising but hope some of you may be interested > to know that I've created an iPad application containing the python > interpreter and a simple execution environment. It's available in iTunes > athttp://itunes.apple.com

Re: Creating unit tests on the fly

2011-04-08 Thread Raymond Hettinger
On Apr 8, 12:10 pm, Roy Smith wrote: > I can even create new test cases from these on the fly with something > like: > >  newClass = type("newClass", (BaseSmokeTest,), {'route': '/my/newly/ > discovered/anchor'}) > > (credit > tohttp://jjinux.blogspot.com/2005/03/python-create-new-class-on-fly.ht

Re: Generators and propagation of exceptions

2011-04-08 Thread Raymond Hettinger
On Apr 8, 12:47 pm, r wrote: > Anyway, thank you all for helping me out and bringing some ideas to > the table. I was hoping there might be some pattern specifically > designed for thiskind of job (exception generators anyone?), which > I've overlooked. If not anything else, knowing that this isn'

Re: Generators and propagation of exceptions

2011-04-08 Thread Raymond Hettinger
On Apr 8, 8:55 am, r wrote: > I had a problem for which I've already found a "satisfactory" > work-around, but I'd like to ask you if there is a better/nicer > looking solution. Perhaps I'm missing something obvious. > > The code looks like this: > > stream-of-tokens = token-generator(stream-of-ch

Re: Generators and propagation of exceptions

2011-04-08 Thread Raymond Hettinger
On Apr 8, 8:55 am, r wrote: > I had a problem for which I've already found a "satisfactory" > work-around, but I'd like to ask you if there is a better/nicer > looking solution. Perhaps I'm missing something obvious. > > The code looks like this: > > stream-of-tokens = token-generator(stream-of-ch

Re: Tips on Speeding up Python Execution

2011-04-08 Thread Raymond Hettinger
On Apr 8, 12:25 am, Chris Angelico wrote: > On Fri, Apr 8, 2011 at 5:04 PM, Abhijeet Mahagaonkar > > wrote: > > I was able to isolate that major chunk of run time is eaten up in opening a > > webpages, reading from them and extracting text. > > I wanted to know if there is a way to concurrently c

Re: Why is __root checked for in OrderedDict?

2011-04-07 Thread Raymond Hettinger
On Apr 7, 2:40 pm, andrew cooke wrote: > Is that normal?  I mean, OK, it's possible (and yes I forgot it could be > called directly), but is there any usual reason to do so? It's common for subclasses to call their parent's __init__ method, so that should emulate dict as nearly as possible to he

Re: Why is __root checked for in OrderedDict?

2011-04-07 Thread Raymond Hettinger
On Apr 7, 4:13 am, andrew cooke wrote: > If you look at the code > inhttp://hg.python.org/cpython/file/6adbf5f3dafb/Lib/collections/__init...the > attribute __root is checked for, and only created if missing.  Why? > > I ask because, from what I understand, the __init__ method will only be > ca

Re: Fun python 3.2 one-liner

2011-04-05 Thread Raymond Hettinger
On Apr 5, 6:38 am, Daniel Fetchinson wrote: > >> what is the character limit on a one liner :P. > > > For PEP 8 compliance, 80 characters. :-) > > Yeah, but we don't live in the 80's or 90's anymore and our screens > can support xterms (or let alone IDE widows) much wider than 80 > characters. I'm

Re: a better way to invert a list?

2011-04-05 Thread Raymond Hettinger
[Ian Kelly] > Which is O(n).  If that is too verbose, you could also use a dictionary: > > def invert(p): >     return dict(map(reversed, enumerate(p))) def inv(p): return dict(zip(p, itertools.count())) Raymond -- http://mail.python.org/mailman/listinfo/python-list

Re: Alias for an attribute defined in a superclass

2011-03-31 Thread Raymond Hettinger
On Mar 31, 3:14 pm, Ben Finney wrote: > Howdy all, > > I want to inherit from a class, and define aliases for many of its > attributes. How can I refer to “the attribute that will be available by > name ‘spam’ once this class is defined”? > >     class Foo(object): >         def spam(self): >    

Re: best python games?

2011-03-30 Thread Raymond Hettinger
On Mar 25, 7:39 pm, sogeking99 wrote: > hey guys, what are some of the best games made in python? free games > really. like pygames stuff. i want to see what python is capable of. > > cant see any good one on pygames site really, though they have nothing > like sort by rating or most downloaded as

Re: Why aren't copy and deepcopy in __builtins__?

2011-03-30 Thread Raymond Hettinger
On Mar 27, 8:29 pm, John Ladasky wrote: > Simple question.  I use these functions much more frequently than many > others which are included in __builtins__.  I don't know if my > programming needs are atypical, but my experience has led me to wonder > why I have to import these functions. I aske

Re: Directly Executable Files in Python

2011-03-30 Thread Raymond Hettinger
On Mar 28, 8:37 pm, Jordan Meyer wrote: > Is it possible to make a directly executable (such as .exe on Windows) file > from scripts written in Python? So as to prevent the end-user from having to > download an interpreter to run the program. http://docs.python.org/faq/programming.html#how-can-

Re: delete namespaces

2011-03-30 Thread Raymond Hettinger
[monkeys paw] > > How do i delete a module namespace once it has been imported? . . . > > Then i make a modification to banner.py. When i import it again, > > the new changes are not reflected. [Terry Reedy] > The best thing, if possible, is to restart the program. > If you develop banner.py with

Re: popular programs made in python?

2011-03-30 Thread Raymond Hettinger
On Mar 29, 7:32 am, Neil Alt wrote: > i mean made with python only, not just a small part of python. BitTorrent was a huge success. Raymond -- http://mail.python.org/mailman/listinfo/python-list

Re: learn python the hard way exercise 42 help

2011-03-30 Thread Raymond Hettinger
On Mar 30, 6:48 am, neil harper wrote: > http://pastie.org/1735028 > hey guys play is confusing me, i get how next gets the first room, which > is passed when the instance of Game() is created, but how does it get > the next room? It might help show calling patterns if you added print statements

Re: Fun python 3.2 one-liner

2011-03-30 Thread Raymond Hettinger
On Mar 30, 2:19 am, Martin De Kauwe wrote: > what is the character limit on a one liner :P. Very interesting > jesting apart, any more? Sure, here are three one-liners using itertools.groupby() to emulate some Unix pipelines: sort letters | uniq # list unique values sort letters | uniq

Dictionary Descriptors

2011-03-30 Thread Raymond Hettinger
On the python-ideas list, someone made a wild proposal to add descriptors to dictionaries. None of the respondents seemed to realize that you could (not should, just could) already implement this using hooks already present in the language. I'm posting an example here because I thought you all mi

Re: delete namespaces

2011-03-29 Thread Raymond Hettinger
On Mar 29, 6:14 pm, monkeys paw wrote: > How do i delete a module namespace once it has been imported? . . . > Then i make a modification to banner.py. When i import it again, > the new changes are not reflected. Is there a global variable i can > modify? In Python2.x, you can use the reload() f

Re: Fun python 3.2 one-liner

2011-03-29 Thread Raymond Hettinger
>>> print('\n'.join('*'*(c//2000) for _,c in sorted(Counter(map(sum, >>> product(range(6), repeat=8))).items( * *** * ** * * **

Fun python 3.2 one-liner

2011-03-29 Thread Raymond Hettinger
from collections import Counter from itertools import product print('\n'.join('*'*(c//2000) for _,c in sorted(Counter(map(sum, product(range(6), repeat=8))).items( almost-normally-yours, Raymond -- http://mail.python.org/mailman/listinfo/python-list

Re: Guido rethinking removal of cmp from sort method

2011-03-28 Thread Raymond Hettinger
On Mar 28, 8:43 am, Steven D'Aprano wrote: > Thank you for spending the time to get some hard data, but I can't > replicate your results since you haven't shown your code. Rather than > attempt to guess what you did and duplicate it, I instead came up with my > own timing measurements. Results are

Re: FW: ciao

2011-03-26 Thread Raymond Hettinger
On Mar 26, 11:34 am, MRAB wrote: > On 26/03/2011 18:07, bledar seferi wrote: > > >     3.Scrivere unafunsioncheprende comeargomentouna lista > >     diinterierestituisce uninsieme contenentequei numerichesono2 o più > >     voltenellalista fornita.Per esempio,seservecomelista di > >     input=[1,2

Re: Understanding the Pystone measurement

2011-03-26 Thread Raymond Hettinger
I forgot to mention that PyStone is just a Python translation from C of the venerable Dhrystone benchmark. See http://en.wikipedia.org/wiki/Dhrystone for a short write-up on the history, purposes, and limitations of the benchmark. Raymond -- http://mail.python.org/mailman/listinfo/python-list

Re: Understanding the Pystone measurement

2011-03-26 Thread Raymond Hettinger
On Mar 24, 9:21 pm, "tleeuwenb...@gmail.com" wrote: > Hi there, > > Is there a good writeup of what the pystone measurement actually > means? I'm working on benchmarking of some Python code at work, and > I'm interested in how Pystone might be relevant to me. I've tried > googling, but I can't fin

Re: Guido rethinking removal of cmp from sort method

2011-03-26 Thread Raymond Hettinger
On Mar 26, 4:39 am, Mark Dickinson wrote: > On Mar 25, 2:00 pm, Stefan Behnel wrote: > > > > > > > > > > > Westley Martínez, 25.03.2011 14:39: > > > > On Fri, 2011-03-25 at 07:11 +0100, Stefan Behnel wrote: > > >> Steven D'Aprano, 25.03.2011 06:46: > > >>> On Thu, 24 Mar 2011 18:32:11 -0700, Carl

Re: An amazing one-minute bit of fun at the interactive prompt

2011-02-21 Thread Raymond Hettinger
On Feb 21, 12:08 am, Mark Dickinson wrote: > On Feb 20, 8:08 am, Raymond Hettinger wrote: > > > [...] > > >>> n * e > > > 3.1415926 > Very neat!  Is it supposed to be obvious why this gives an > approximation to pi?  If so, I'll think about it a

Re: An amazing one-minute bit of fun at the interactive prompt

2011-02-20 Thread Raymond Hettinger
> Compute ð ± e by counting Mandlebrot set iterations :-) That should be: pi plus-or-minus e Raymond -- http://mail.python.org/mailman/listinfo/python-list

An amazing one-minute bit of fun at the interactive prompt

2011-02-20 Thread Raymond Hettinger
>>> e = 10.0 ** -7; n = 0; z = c = complex(-0.75, e) >>> while abs(z) < 2.0: n += 1 z = z * z + c >>> n * e 3.1415926 Compute π ± e by counting Mandlebrot set iterations :-) Raymond -- http://mail.python.org/mailman/listinfo/python-list

Re: IDLE: A cornicopia of mediocrity and obfuscation.

2011-02-01 Thread Raymond Hettinger
On Jan 31, 9:39 am, rantingrick wrote: > IDLE: cornucopia ... > These are just the top of the list. The peak of a huge iceberg that > threatens to sink the community in the arms of chaos never to return. That being said, I've taught a lot of people Python using IDLE. It's a surprisingly producti

Re: Use the Source Luke

2011-01-31 Thread Raymond Hettinger
On Jan 30, 6:47 am, Tim Wintle wrote: > +1 - I think the source links are very useful (and thanks for pushing > them). Happy to do it. > However I think the biggest changes that have probably happened with > python itself are: > >  (1) More users for whom this is their first language. >  (2) CS

Re: Use the Source Luke

2011-01-29 Thread Raymond Hettinger
On Jan 28, 3:10 pm, Ben Finney wrote: > Raymond Hettinger writes: > > The rest of the blame lies with installers. They all treat > > human-readable scripts like they were binaries and tuck the code away > > in a dark corner. > > That’s hardly a “blame” of installers

Re: Use the Source Luke

2011-01-29 Thread Raymond Hettinger
On Jan 29, 3:22 am, TP wrote: > On Fri, Jan 28, 2011 at 10:32 AM, Raymond Hettinger wrote: > > I hoping a new trend will start with dev's putting direct > > source code links in their documentation: > > >  http://rhettinger.wordpress.com/2011/01/28/open-your-sourc

Re: Use the Source Luke

2011-01-28 Thread Raymond Hettinger
[Jack Diedrich] > I think you overestimate how common it used to be to carry around the > sourcecode for the software you use compared to now;  In the past it > wasn't even always possible - if the Sun cc compiler core dumps you > have no recourse to code. You're right of course. For the Python w

Use the Source Luke

2011-01-28 Thread Raymond Hettinger
I hoping a new trend will start with dev's putting direct source code links in their documentation: http://rhettinger.wordpress.com/2011/01/28/open-your-source-more/ I'm looking for more examples of projects that routinely link their docs back into relavant sections of code. Have any of you all

Re: Wrappers in python

2011-01-27 Thread Raymond Hettinger
On Jan 27, 4:10 am, sl33k_ wrote: > What are wrappers? > >  What entities do they wrap around? > > Struggling to understand the concept. http://www.castle-cadenza.demon.co.uk/wrapper.htm Raymond -- http://mail.python.org/mailman/listinfo/python-list

Re: UTF-8 question from Dive into Python 3

2011-01-18 Thread Raymond Hettinger
On Jan 17, 2:19 pm, carlo wrote: > Hi, > recently I had to study *seriously* Unicode and encodings for one > project in Python but I left with a couple of doubts arised after > reading the unicode chapter of Dive into Python 3 book by Mark > Pilgrim. > > 1- Mark says: > "Also (and you’ll have to t

Re: move to end, in Python 3.2 Really?

2011-01-17 Thread Raymond Hettinger
On Jan 17, 6:51 pm, nn wrote: > ...But the api on this baffles me a bit: > > >>> d = OrderedDict.fromkeys('abcde') > >>> d.move_to_end('b', last=False) > >>> ''.join(d.keys) > > 'bacde' > > I understand that "end" could potentially mean either end, but would > "move_to_end" and "move_to_beginning"

Re: Needed: Real-world examples for Python's Cooperative Multiple Inheritance

2010-11-28 Thread Raymond Hettinger
On Nov 28, 4:36 am, coldpizza wrote: > Did you try google code search? It is *not* the same as google code > hosting. > The site ishttp://www.google.com/codesearchand you can select Python > in the 'language' dropdown. Yes, I use Google's code search frequently and did try it for super(). However

Re: Needed: Real-world examples for Python's Cooperative Multiple Inheritance

2010-11-25 Thread Raymond Hettinger
[Paul Rubin] > I'd mention the SocketServer library, except I'm not sure what you > mean by "cooperative", so I don't know if that counts. Cooperative multiple inheritance is a specific problem when there is a diamond diagram with the same method name needing to be called on multiple paths and eac

Re: Needed: Real-world examples for Python's Cooperative Multiple Inheritance

2010-11-25 Thread Raymond Hettinger
On Nov 25, 3:38 pm, John Nagle wrote: >     Multiple inheritance in Python is basically what fell out of > CPython's internals, not a design.   Sorry to disagree. That is historically inaccurate. Guido designed super() on purpose. He took his cues from "Putting Metaclasses to Work" by Ira Forma

Re: Needed: Real-world examples for Python's Cooperative Multiple Inheritance

2010-11-25 Thread Raymond Hettinger
On Nov 24, 9:16 pm, Alice Bevan–McGregor wrote: > On 2010-11-24 12:08:04 -0800, Raymond Hettinger said: > > > I'm writing-up more guidance on how to use super() and would like to > > point at some real-world Python examples of cooperative multiple > > inheritance

Needed: Real-world examples for Python's Cooperative Multiple Inheritance

2010-11-24 Thread Raymond Hettinger
I'm writing-up more guidance on how to use super() and would like to point at some real-world Python examples of cooperative multiple inheritance. Google searches take me to old papers for C++ and Eiffel, but that don't seem to be relevant to most Python programmers (i.e. a WalkingMenu example whe

Re: [RELEASED] Python 3.2 alpha 3

2010-11-16 Thread Raymond Hettinger
On Nov 16, 9:23 am, Mark Summerfield wrote: > I think it might be worth mentioning in What's New: FWIW, I'll be updating the What's New document for the Beta. Raymond -- http://mail.python.org/mailman/listinfo/python-list

Is a 32-bit build faster than a 64-bit build

2010-11-12 Thread Raymond Hettinger
Has anyone here benchmarked a 32-bit Python versus a 64-bit Python for Django or some other webserver? My hypotheses is that for apps not needing the 64-bit address space, the 32-bit version has better memory utilization and hence better cache performance. If so, then switching python versions ma

Re: Split iterator into multiple streams

2010-11-06 Thread Raymond Hettinger
On Nov 6, 1:52 am, Steven D'Aprano wrote: > I tried changing the t[i] to use operator.itergetter instead, but no > luck. Finally I got this: > > def split(iterable, n): >     iterators = [] >     for i, iterator in enumerate(itertools.tee(iterable, n)): >         f = lambda it, i=i: (t[i] for t in

Re: Final state of underlying sequence in islice

2010-11-05 Thread Raymond Hettinger
On Nov 5, 3:52 pm, Ian wrote: > On Nov 5, 2:51 pm, Raymond Hettinger wrote: > > > You may have missed my point.  I wrote the tools, the docs, and the > > tests. > > If you interpret a "promise" in text, I can assure you it was not > > intended.  The

Re: Final state of underlying sequence in islice

2010-11-05 Thread Raymond Hettinger
On Nov 5, 1:05 pm, Terry Reedy wrote: > > Currently, there are no promises or guarantees about the final state > > of the iterator. > > I interpret the current doc statement as a promise that becomes > ambiguous when step > 1. You may have missed my point. I wrote the tools, the docs, and the te

Re: Final state of underlying sequence in islice

2010-11-05 Thread Raymond Hettinger
>  Shashank Singh wrote: > > > Are there any promises made with regard to final state of the underlying > > sequence that islice slices? Currently, there are no promises or guarantees about the final state of the iterator. To the extent the pure Python version in the docs differs from the CPytho

  1   2   3   4   5   6   7   8   >