The following works as expected:
d = [(1,2), (3,4)]
for k,v in d:
print "%s - %s" % (str(k), str(v))
But this fails:
d = collections.defaultdict(int)
d[1] = 2
d[3] = 4
for k,v in d:
print "%s - %s" % (str(k), str(v))
With:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'int' object is no...
I want to build a simple application that looks up words against Wiktionary to see if they exist. Is there a standard API supported by the Wiktionary software that would let me do this? Alternatively, is there any way I can pull down the dictionary data that backs a Wiktionary? There are many international variants who's data I would ...
Hi all,I want to develop an iphone application that needs an english word dictionary. Can you people suggest me any link from where i can have that database containing a reasonable number of english words with their meanings and example sentence.
Thanks in advance
...
Hi folks,
I have a C#-Application that stores data from a TextFile in a Dictionary-Object. The amount of data to be stored can be rather large, so it takes a lot of time inserting the entries. With many items in the Dictionary it gets even worse, because of the resizing of internal array, that stores the data for the Dictionary.
So I in...
Hello,
I have a list of dicts and I want to compare each dict in that list with a dict in a resulting list, add it to the result list if it's not there, and if it's there, update a counter associated with that dict.
At first I wanted to use the solution described at http://stackoverflow.com/questions/1692388/python-list-of-dict-if-exis...
We have a class "Foo" which requires some limited security. In particular, we have defined Authors, Editors, Owners, and Account Managers (aka RoleManager) for each 'foo'.
The DB mapping table contains a FooID, a UserID, and an integer (binary representation of flags) which are used to determine which of those 4 roles you have on which...
One way to manually persist a dictionary to a database is to flatten it into a sequence of sequences and pass the sequence as an argument to cursor.executemany().
The opposite is also useful, i.e. reading rows from a database and turning them into dictionaries for later use.
What's the best way to go from myseq to mydict and from mydic...
I have a file of names and addresses as follows (example line)
OSCAR ,CANNONS ,8 ,STIEGLITZ CIRCUIT
And I want to read it into a dictionary of name and value. Here self.field_list is a list of the name, length and start point of the fixed fields in the file. What ways are there to speed up this method? (python 2.6)
de...
Here's what I'm trying to do:
ObjectA
{
int ID;
string name;
}
I want to convert Dictionary to List where the strings in the list are the .name values of the ObjectAs in the dictionary. Obviously I could manually iterate over the dictionary values and build the list that way, but I was hoping there'd be a simpler or faster wa...
Where can I find good implementation of IDictionary which uses weak references inside?
Dictionary should be holding only weak references to values and eventually clean up itself of dead references.
Or should I just write it myself?
...
if I've string like
"{ partner_name = test_partner}" OR " { partner_name : test_partner }
its an example string will be very complex with several special characters included like =, [ , ] , { , }
what will be the best way to convert it into a python object - so I can process it
I tried with eval but it requires " ' " for string, but...
Using the API, trying to get items in a specific feed returns this:
{“direction”:”ltr”,”id”:”feed/http://arstechnica.com/index.rssx”,”title”:”Ars Technica”,”description”:”The Art of Technology”,”self”:[{"href":"http://www.google.com/reader/api/0/stream/contents/feed/http://arstechnica.com/index.rssx?ot\u003d1273193172856169\u0026r\u003d...
I'm a non-VB6 person who had the misfortune of inheriting a buggy legacy VB6/Classic ASP project. There's a section where a lot of entries are put into a Dictionary and I want to see all it contains. I tried this (oParams is a Dictionary):
Dim o As Object
Dim sDicTempAggr As String
sDicTempAggr = ""
For Each o In oParams
sDicTempAgg...
exhaustive:
- all keys in the dictionary, even if the keys are in a nested dictionary that is a value to a previous-level dictionary key.
sorted:
- this is to ensure the keys are always returned in the same order
The nesting is arbitrarily deep. A non-recursive algorithm is preferred.
level1 = {
'a' : 'aaaa',
'level2_1...
When using immutable dictionaries in F# , how much overhead is there when adding / removing entries?
Will it treat entire buckets as immutable and clone those and only recreate the bucket whos item has changed?
Even if that is the case, it seems like there is alot of copying that needs to be done in order to create the new dictionary(?...
Hi all,
This is a really really super dumb question, so I apologise, but I'd be grateful for some advice.
I've got a text file of words and word frequencies. It's very large - theoretically we're talking millions of rows.
I just want to retrieve values from the file, and do it as quickly and efficiently as possible (for a web app, i...
I've got a Dictionary<string, string> and would like to have the user to see and edit the content, possibly adding new entries. How should I do that?
Input verification, handling dynamic updates of the source Dictionary and looking nice are a bonus.
...
d3 = dict(d1, **d2)
I understand that this merges the dictionary. But, is it unique? What if d1 has the same key as d2 but different value? I would like d1 and d2 to be merged, but d1 has priority if there is duplicate key.
...
Basically, I want to take a
Dictionary like { "a":"bar", "b":"blah", "c":"abc", "d":"nada" }
and use it to set variables (in an Object) which have the same name as a key in the dictionary.
class Foo(Object)
{
self.a = ""
self.b = ""
self.c = ""
}
So in the the end self.a = "bar", self.b = "blah", etc... (and key "d" is ...
I'm trying to construct a dictionary that contains a series of sets:
{Field1:{Value1, Value2, Value3}, Field2{Value4}}
The trouble is, I then wish to delete any fields from the dictionary that only have one value in the set. I have been writing code like this:
for field in FieldSet:
if len(FieldSet[field]) == 1:
del(FieldSet[fie...