Mr. Brewer:
I fruitlessly tried your "thing counter", as you can see below. class AllThingsStartAtZero(dict):
.... def getitem (self, key):
.... return dict.get(self, key, 0)
.... thingCounts = AllThingsStartAtZero() for thing in ('a','b','c','d','a'):
.... thingCounts[thing] += 1
....
Traceback (most recent call last):
File "<interactive input>", line 2, in ?
KeyError: 'a' thingCounts
{}
Reason tells me it should work for me using...
PythonWin 2.3.4 (#53, May 25 2004, 21:17:02) [MSC v.1200 32 bit
(Intel)] on win32.
....as it did for you. The runtime interpreter, however, says
otherwise. Can you see what I've done wrong...I can't?
With thanks in advance, I am,
Respectfully yours,
Fred Allen 1 1508 fa****@leveltwo.com (Fred Allen) wrote in
news:72**************************@posting.google.c om: Mr. Brewer:
I fruitlessly tried your "thing counter", as you can see below.
class AllThingsStartAtZero(dict): ... def getitem (self, key):
it's __getitem__ note the underlines.
... return dict.get(self, key, 0) ... thingCounts = AllThingsStartAtZero() for thing in ('a','b','c','d','a'): ... thingCounts[thing] += 1 ... Traceback (most recent call last): File "<interactive input>", line 2, in ? KeyError: 'a' thingCounts
{}
Reason tells me it should work for me using...
PythonWin 2.3.4 (#53, May 25 2004, 21:17:02) [MSC v.1200 32 bit (Intel)] on win32.
...as it did for you. The runtime interpreter, however, says otherwise. Can you see what I've done wrong...I can't?
With thanks in advance, I am,
Respectfully yours,
Fred Allen This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: gabriele renzi |
last post by:
Hi gurus and nubys,
matz said more than once that the perlish global variables like
$/ or $: are going away in future releases.
I wonder if is there already a decision, what they will become?...
|
by: Chris |
last post by:
One nice thing about Perl that is helpful when tallying things up by
type is that if you increment a hash key and the key does not exist,
Perl puts a one there. So you can have code that does...
|
by: Raymond Hettinger |
last post by:
I would like to get everyone's thoughts on two new dictionary methods:
def count(self, value, qty=1):
try:
self += qty
except KeyError:
self = qty
def appendlist(self, key, *values):
try:
|
by: Talin |
last post by:
I want to make a dictionary that acts like a class, in other words,
supports inheritance: If you attempt to find a key that isn't present,
it searches a "base" dictionary, which in turn searches...
|
by: Christoph Zwerschke |
last post by:
Ok, the answer is easy: For historical reasons - built-in sets exist
only since Python 2.4.
Anyway, I was thinking about whether it would be possible and desirable
to change the old behavior in...
|
by: Matt Kruse |
last post by:
Perl's map() function is a powerful shortcut to accomplish many "loop over
an array and do X" operations.
Below is a quick hack to simulate similar functionality.
I've used it a few times and find...
|
by: Brian Richards |
last post by:
I'm experiencing some wierd behavior with a Dictionary<T,U> class using
foreach loops, such that the Key returned in the foreach is not contained in
the dictionary.
code:
Dictionary<A, B>...
|
by: akameswaran |
last post by:
I wrote up a quick little set of tests, I was acutally comparing ways
of doing "case" behavior just to get some performance information. Now
two of my test cases had almost identical results which...
|
by: Almad |
last post by:
Hello,
I discovered this behaviour in dictionary which I find confusing. In
SneakyLang, I've tried to extend dictionary so it visits another class
after something is added:
class...
|
by: James Mills |
last post by:
On Fri, Oct 31, 2008 at 8:49 AM, mark floyd <emfloyd2@gmail.comwrote:
Mark, this is correct behavior. You have
3 positional arguments in the function
definition. You _must_ aupply _all_ 3
of...
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
| |