I spent some time thinking of various techniques and benchmarking them. It turns out the simplest is the fastest. Copy the iterator into a list and see how big the list is. I find that surprising since the data must be copied into a flat array that must occasionally be resized.
The fastest solution I like is to copy the iterator into a fixed size list, until the iterator is empty. That is about 3x faster than a simple for loop.
Here's a link to my data and a basic description of the different techniques. I'd love for someone to surprise me with something new and novel!
The opposite of 'append' is 'prepend'. So the opposite of 'extend' is 'pretend'? OK, that is funny but terrible, but what is the right method name?
Free stream at 11AM.
My biggest problem is that they return booleans. Unlike the flexibility I get from the logical `and` and `or` operators, which result in the last value that was evaluated.
This change alone would make `any` and `all` more useful. For example, if I had a list of strings and I wanted to find a string that was non-empty, I could use "any(my_sparse_strings)" to fetch it. This becomes the same as doing "my_sparse_strings or my_sparse_strings or .. my_sparse_strings[n]".
They become more useful if we also add a "key" argument to transform the values. This might be just as useful as the key function in `sort`, `min`, and `max`. I'm still not sure about this because you then cannot know if the value returned met or did not meet the criteria, without checking it again.
Lastly, did you know `all` generates a `True` for an empty list and `any` generates `False` for an empty list? It seems like it would be convenient to control the value when given an empty iteratable.
Well, I took a stab at improving both of these in my yter library. See the `yall` and `yany` methods. I was highly tempted to name them `yand` and `yor`, but I steered towards naming them after the existing Python functions.
I've been writing a few iterators and doing some simple benchmarking. I was suprised to see that python classes are nearly an order of magnitude slower than a generator.
I've documented my findings and shared them on my new, barely interesting library of iterators.
TLDR, use combinations of itertools if at all possible, otherwise go for a generator, and never build a class with a next method!
If we change your version to "it = iter(i)" then that improves performance to only 3x slower than a generator! I'm still convinced the conclusion is correct.
Pandora Radio - Listen to Free Internet Radio, Find New Music
Pandora radio is the personalized internet radio service that helps you find new music based on your old and current favorites. Create custo
Paris 1900-2013 en photos : grimpez dans notre fabuleuse machine à remon...
Dix autochromes, commandés par un riche banquier, de la capitale au siècle dernier... en face de dix photos, prises par nous cette année. Ru
PyCharm 2.7 is available: back to core Python | JetBrains PyCharm Blog
We've released PyCharm 2.7, a big update for our Python and Django IDE. The main focus of this update is better Python coding experience. We
Graydon’s work on Mozilla » Blog Archive » Rust 0.1 release
Another six months and we have our first release. Rust is now at a point where we'd like to invite people to write code in it. It's
PyCharm 2.5 Released! A Really Environment Friendly IDE | JetBrains PyCh...
Hurray! We made it! PyCharm 2.5 is officially available. PyCharm has been green since its version one, but this update makes it truly enviro
Portal 2 is Games Radar's Most Favorite 2011 Video Game
Their readers thought the best video game of 2011 was Skyrim, but the editors of Games Radar have picked Portal 2. It's their top game of th
4K Download | Free, useful applications for all modern plaforms
Free, useful applications for all modern platforms. Download video and audio from YouTube or photos from Instagram, make slideshows. And muc
Installing Amazon MP3 Downloader on Ubuntu 11.04 | dgf64art
Installing Amazon MP3 Downloader on Ubuntu 11.04. Posted by dgf64 on Jul 5, 2011 in Application, Main Topics, Tutorials | 4 comments. Not ev