Ordered dictionaries: Example 29 provides us with a SortableDict class, found in the collections module. What Python 3.1 gives us is a little different, though. It just keeps the order that you passed in the items. In addition to all of the normal dict methods, this new class has a method OrderedDict.popitem(last=True) that will pop the last (or first, if last is set to False) item off of the object, much like list.pop(). Note that if you change the value of an item, the order will not change. If you remove that item and then add it back in, the item will then go to the back. Here's how to use the OrderedDict class in 3.1 (using Dr. Punch's example29.demo() example values):
And the output...
String formatting, the new way. As you probably have read in my first post, the format method on strings is the preferred way to format strings... but it seems kind of silly to number each format part if you're just going in order (like we're used to with the % operator):
"I asked my friend {0}, and I asked my friend {1}; they said it was {2}!".format("Joe", "Jake", "fhqwhgads")
Well now, with Python 3.1 (RC1 is out), you can do this:
"I asked my friend {}, and I asked my friend {}; they said it was {}!".format("Joe", "Jake", "fhqwhgads")
and you will get the same formatted output. Of course, the numbering method will still work (and is still necessary if you want to be playing with the order of the format strings).
Also format-related, check this out (the comma means to add decimal separators, everything else has been around since 2.6/3.0... "0" says the first argument to format, ":" means to do manipulation, ".2" means 2-precision, "f" means to "coerce" to float):
>>> "{0:,.2f}".format(123456789)
'123,456,789.00'
That's right, human-readable decimals with string formatting!
(Combine this new change with the previous one and you get this:)
>>> "{:,.2f}".format(123456789)
'123,456,789.00'
More to come when I get time.

2 comments:
Making money on the internet is easy in the hush-hush world of [URL=http://www.www.blackhatmoneymaker.com]blackhat team[/URL], It's not a big surprise if you haven’t heard of it before. Blackhat marketing uses not-so-popular or not-so-known methods to build an income online.
[url=http://www.23planet.com]online casino[/url], also known as accepted casinos or Internet casinos, are online versions of household ("hunk and mortar") casinos. Online casinos consign gamblers to hand-picked up and wager on casino games painstakingly the Internet.
Online casinos typically nervous up championing swap odds and payback percentages that are comparable to land-based casinos. Some online casinos turn one's back on higher payback percentages applicable low gathering games, and some induce known payout proportion audits on their websites. Assuming that the online casino is using an fittingly programmed indefinitely hundred generator, in first of games like blackjack enquire an established heritage edge. The payout ditty track of these games are established late the rules of the game.
Assorted online casinos sublease or apprehension their software from companies like Microgaming, Realtime Gaming, Playtech, Supranational Run Technology and CryptoLogic Inc.
Post a Comment