Linked Questions
14 questions linked to/from When should iteritems() be used instead of items()?
481 votes
17 answers
494k views
Get the key corresponding to the minimum value within a dictionary
If I have a Python dictionary, how do I get the key to the entry which contains the minimum value? I was thinking about something to do with the min() function... Given the input: {320:1, 321:0, ...
163 votes
19 answers
181k views
How do I exchange keys with values in a dictionary? [duplicate]
I receive a dictionary as input, and would like to to return a dictionary whose keys will be the input's values and whose value will be the corresponding input keys. Values are unique. For example, ...
137 votes
10 answers
247k views
How can I consume a WSDL (SOAP) web service in Python?
I want to use a WSDL SOAP based web service in Python. I have looked at the Dive Into Python code but the SOAPpy module does not work under Python 2.5. I have tried using suds which works partly, but ...
24 votes
7 answers
13k views
How do I copy **kwargs to self?
Is there a way that I can define __init__ so keywords defined in **kwargs are assigned to the class? For example, if I were to initialize a ValidationRule class with ValidationRule(other='email'), ...
5 votes
2 answers
6k views
Iterator for custom class in Python 3
I'm trying to port a custom class from Python 2 to Python 3. I can't find the right syntax to port the iterator for the class. Here is a MVCE of the real class and my attempts to solve this so far: ...
4 votes
5 answers
10k views
Function to check if object-dtype column value is float or string
I am trying to write a function which is equal to isnumber[column] function in excel dataset: feature1 feature2 feature3 123 1.07 1 231 2.08 3 122 ab 4 111 ...
4 votes
1 answer
2k views
Enumerating through a dictionary in Python [duplicate]
I am trying to enumerate through a dictionary like this but it does not work. What's the simplest way to iterate through a dictionary in python while enumerating each entry? for i, k, v in enumerate(...
0 votes
5 answers
164 views
Iterate over dictionary of class containing a list
I have something like this: class C: def get_data(): returns a list d = {several instances of C} Now, how do I iterate over all elements of all lists? I failed miserably: [e for e in [v.get_data()...
0 votes
1 answer
2k views
Python Opencv 'numpy.ndarray' object has no attribute 'iteritems'
Recently I have been working on an object recognizer. Some of the code written below is copied. When I ran the code I got this weird error:AttributeError: 'numpy.ndarray' object has no attribute '...
0 votes
3 answers
469 views
Groupby in a list for python
Given a large dataset of one million records, I am looking for ways to do a group by. I am new to python, but i know in SQL there's a groupby function and i am guessing it might be applicable. What ...
-1 votes
2 answers
178 views
Combing two dictionaries with a key and an element in each key (python)
I have two dictionaries: Let's say MaleDict = {'Jason':[(2014, 394),(2013, 350)...], 'Stephanie':[(2014, 3), (2013, 21),..]....} FemaleDict = {'Jason':[(2014, 56),(2013, 23)...], 'Stephanie':[(2014,...
-7 votes
3 answers
77 views
How do I get a dictionary into a list of all the keys in the following format? (In python) [closed]
Given a dictionary { 'a': [1, 2, 3], 'b': [4, 5, 6] } how do I get the output [ ['a', 1, 2, 3], ['b', 4, 5, 6] ]
-2 votes
1 answer
61 views
How do I better use the translate function?
If I want to use translate on more than one unicode character like: 'banana'.translate({ord('ba'):u'cd'}) How can I do this? ord works on only one character. So what can make this happen? Note: The ...
-3 votes
2 answers
49 views
Getting values from a dict in 2nd field [closed]
For example, I have this: alphabetValues = {"a":1,"b":2,"c":3,"d":4,"e":5,"f":6,"g":7... Is it possible if instead of having: print(alphabetValues["c"]) To having something that would get "e" if I ...