Is there a good way to store a Python dictionary in the datastore? I want to do something like the following:
from google.appengine.ext import db
class Recipe(db.Model):
name = db.StringProperty()
style = db.StringProperty()
yeast = db.StringProperty()
hops = db.ListofDictionariesProperty()
Of course, that last line doesn't ...
I am trying to create a small server type application and have a question regarding organizing data with dicts. Right now I am grouping the data using the connection socket (mainly to verify where it's coming from and for sending data back out). Something like this: connected[socket] = account_data. Basically, each connected person will ...
Say you have,
foo = 'bar'
d = {'a-key':'a-value'}
And you want
d = {'a-key':'a-value','foo':'bar'}
e = {'foo':foo}
I know you can do,
d['foo'] = foo
#Either of the following for e
e = {'foo':foo}
e = dict(foo=foo)
But, in all these way to add the variable foo to dict, I have had to use the word foo twice; once to indicate the k...
This might sound like a stupid question, but I had a long talk with some of my fellow developers and it sounded like a fun thing to think of.
So; what's your thought - what does a Regex look like, that will never be matched by any string, ever!
Edit: Why I want this? Well, firstly because I find it interesting to think of such an expre...
Is there a way to do something like the following in Django templates?
{% for hop in hops%}
<tr>
<td>{{ hop.name }}</td>
<td>{{ hop.mass }}</td>
<td>{{ hop."boil time" }}</td>
</tr>
{% endfor %}
The hop."boil time" doesn't work. The simple solution is rename the key boil_time, but I'm interested in alt...
Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single instances? I gotta say I only recently started getting into Python but its making this project so much easier. I'm just a bit stumped on this kin...
Hi
I usually do C# but have inherited a classic ASP project.
I have defined a class:
Class clsPayment
Public Name
End Class
Set objPayment = New clsPayment
objPayment.Name = "StackOverflow payment"
And a dictionary:
Set colPayments = CreateObject("Scripting.Dictionary")
colPayments.Add 1, objPayment
When rea...
Okay, this could be rather in depth but I'll try to ask a clear question: how can I find the first value in a Dictionary<int, MyTableClass> where MyTableClass inherits Field<F1, F2, F3>? I'd prefer a Property or Property/Method combination that returns the first value in the Dictionary where F1 = MyEnum.value.
What I don't want to do is...
Hi,
I'm looking for a good name for a custom dictionary which automatically initializes the value for a requested key if it doesn't exist, using a delegate. The indexer implementation should help understand what it does :
public V this[K key]
{
get
{
V value;
if (!_dictionary.TryGetValue(...
How can I determine if any of the list elements are a key to a dict?
The straight forward way is,
for i in myList:
if i in myDict:
return True
return False
but is there a faster / more concise way?
...
I recently did a class assignment where I made a really hacky data structure. I ended up using nested hashes, which seems like a good idea, but is really hard to iterate through and manage.
I was doing general stuff, like one tag maps to a hash of items that map to prices and stuff like that. But some of them were getting more complicat...
I like the python list comprehension operator (or idiom, or whatever it is).
Can it be used to create dictionaries too? For example, by iterating over pairs of keys and values:
dict = {(k,v) for (k,v) in blah blah blah} # doesn't work :(
...
Data structure is a dictionary, each value is another dictionary, like:
>>> from lib import schedule
>>> schedule = schedule.Schedule()
>>> game = schedule.games[0]
>>> game.home
<lib.schedule.Team instance at 0x9d97c6c>
>>> game.home.lineup
{'guerv001': {'HR': 392, '1B': 1297}, 'kendh001': {'HR': 12, '1B': 201}, 'andeg001': {'HR': 272,...
How can I take the opt result of
opt, args = parser.parse_args()
and place it in a dict? Python calls opt a "Values Instance" and I can't find any way to turn a Values Instance into a list or dict. One can't copy items from opt in this way,
for i in opt:
myDict[i] = opt[i]
instead, its a clumsy,
myDict[parm1] = opt.parm1
myDic...
I would like to know the best way to remove the oldest element in a dictionary in order to control the maximum dictionary size.
example:
MAXSIZE = 4
dict = {}
def add(key,value):
if len(dict) == MAXSIZE:
old = get_oldest_key() # returns the key to the oldest item
del dict[old]
dict[key] = value
add('a','1') # {'a': '1'}
ad...
A Python function object has an attribute dictionary called func_dict which is visible from outside the function and is mutable, but which is not modified when the function is called. (I learned this from answers to a question I asked yesterday (#1753232): thanks!) I was reading code (at http://pythonprogramming.jottit.com/functional%...
Does there exist something like Canadian to US english e-dictionary which I can use in my application ?
...
What is the difference between a List of KeyValuePair and a Dictionary for the same types? Is there an appropriate time to use one or the other?
...
I have the following code:
TYPES = {'hotmail':{'type':'hotmail', 'lookup':'mixed', 'dkim': 'no', 'signatures':['|S|Return-Path: [email protected]','|R|^Return-Path:\s*[^@]+@(?:hot|msn)','^Received: from .*hotmail.com$']},
'gmail':{'type':'gmail', 'lookup':'mixed', 'dkim': 'yes', 'signatures':['|S|Subject: unsubscri...
istead of using Dictionary I want some type of collection class that can use a property of the value as the key, is there something like this?
...