Hello,
Any comments on the below mentioned problem are most appreciated.
I have a function and it is throwing this error: - FEXpython_v2.py", line 32, in UnitHolderDistributionqty
-
count[item]+=1
-
KeyError: 3
This is the function: - def Distributionqty(dictionary):
-
holder=list()
-
held=list()
-
distqtydic={}
-
count={}
-
for key in sorted(dictionary.keys()):
-
holder.append(key)
-
held.append(len(dictionary[key]))
-
for (key, value) in map(None, holder, held):
-
distqtydic[key]=value
-
for item in distqtydic.values():
-
count[item]+=1
-
for k,v in sorted(count.items()):
-
fdist=k
-
qty=v
-
print fdist,qty
Not sure why.
G.
3 12850
Hello,
Any comments on the below mentioned problem are most appreciated.
I have a function and it is throwing this error: - FEXpython_v2.py", line 32, in UnitHolderDistributionqty
-
count[item]+=1
-
KeyError: 3
This is the function: - def Distributionqty(dictionary):
-
holder=list()
-
held=list()
-
distqtydic={}
-
count={}
-
for key in sorted(dictionary.keys()):
-
holder.append(key)
-
held.append(len(dictionary[key]))
-
for (key, value) in map(None, holder, held):
-
distqtydic[key]=value
-
for item in distqtydic.values():
-
count[item]+=1
-
for k,v in sorted(count.items()):
-
fdist=k
-
qty=v
-
print fdist,qty
Not sure why.
G.
You need something like this: -
for item in distqtydic.values():
-
if distqtydic.has_key(item):
-
count[item]+=1
-
else:
-
count[item] = 1
-
bartonc 6,596
Recognized Expert Expert
Going back to your first lesson, your keys are strings (as in '3'), if you haven't changed things too much since then. In that case, you'd use:
but I don't recall at this moment if the what type target value is. If it is an int, it may or may not (don't recall) be passed by reference. If you can give a sample of the argument, that would help a lot.
Hi.
I was able to work out with the following: - def UnitHolderDistributionqty(dictionary):
-
from collections import defaultdict
-
count=defaultdict(int)
-
for item in dictionary.values():
-
count[len(item)]+=1
-
for k,v in sorted(count.items()):
-
fdist=k
-
qty=v
-
print fdist,qty
Thanks again.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Norman Shelley |
last post by:
Is there a way to get at the object one is trying to access with a key to list
out all the possible keys?
See the except clause below.
#!/usr/bin/env python2.2
from inspect import *
import sys
program = """
abc = {}
|
by: |
last post by:
Hello.
Maybe someone will help me with this KeyError:
.............................
Traceback (most recent call last):
File "C:\Python\tabla.py", line 929, in -toplevel-
tablesDirectory = tablesDirectoryPrefix + os.environ
File "C:\Python23\lib\os.py", line 417, in __getitem__
return self.data
KeyError: 'REMOTE_ADDR'
|
by: Rune Strand |
last post by:
I'm experiencing strange errors both with pickle and cPickle in the
below code:
import cPickle as pickle
#import pickle
from string import ascii_uppercase
from string import ascii_lowercase
def createData():
|
by: Peter Olcott |
last post by:
www.halting-problem.com
|
by: Jon Davis |
last post by:
If I have a class with a virtual method, and a child class that overrides
the virtual method, and then I create an instance of the child class AS A
base class...
BaseClass bc = new ChildClass();
.... and then call the virtual method, why is it that the base class's method
is called instead of the overridden method? How do I fix this if I...
| |
by: homepricemaps |
last post by:
i have an
href which looks like this:
<td class="all">
<a class="btn" name="D1" href="http://www.cnn.com">
</a>
here is my code
|
by: nyenyec |
last post by:
urllib.quote chokes on unicode in 2.4.4.
2.4.4 (#1, Oct 18 2006, 10:34:39)
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File
"/Library/Frameworks/Python.framework/Versions/2.4//lib/python2.4/urllib.py",
line 1117, in quote
res = map(safe_map.__getitem__, s)
|
by: christof |
last post by:
Hi,
I am using pickle/unpickle to let my program save its documents to
disk. While this it worked stable for a long time, one of my users now
complained, that he had a file which can't be loaded.
The traceback is:
File "pickle.pyo", line 1374, in loads
File "pickle.pyo", line 858, in load
|
by: josh001 |
last post by:
I'm trying to figure out why KeyError: 0 pops up when I try to run the program containing the code.
OpenDLG = wx.FileDialog(
self.win,
message='Please choose the quiz or quizes that you wish to use.',
defaultDir=os.getcwd(),
defaultFile='',
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it. ...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...
| |