Tagged Questions
2
votes
2answers
57 views
Python - KeyError while creating an index
Here is the code (it runs inside class):
if profile['profile_picture']:
profile['profile_picture_raw_path'], # Line 26
profile['profile_picture_thumbnail'],
profile['profile_picture'] = ...
5
votes
2answers
93 views
Making the leap from PhP to Python
I am a fairly comfortable PHP programmer, and have very little Python experience. I am trying to help a buddy with his project, the code is easy enough to write in Php, I have most of it ported over, ...
6
votes
4answers
3k views
Union of dict objects in Python [duplicate]
How do you calculate the union of two dict objects in Python, where a (key, value) pair is present in the result iff key is in either dict (unless there are duplicates)?
For example, the union of ...
0
votes
2answers
134 views
changing value in nested dictionary python using class
class warehouse:
def __init__(self):
self.A={}
self.B={}
self.racks={'A':self.initialize(self.A),'B':self.initialize(self.B)}
def initialize(self,rack):
...
2
votes
2answers
84 views
__hash__ for javascript?
Is there a way to give objects in js custom hashes, just as overriding
__hash__()
in python let's someone define how a given object is hashed into a dictionary.
My underlying question is: what ...
0
votes
3answers
281 views
iterating one key in a python multidimensional associative array
I'm dynamically creating a 2 dimensional associative array (dictionary?)
I'm trying to loop through its keys - while keeping one of the indexes constant, so for instance all of the values associated ...
6
votes
8answers
8k views
java and python equivalent of php's foreach($array as $key => $value)
In php, one can handle a list of state names and their abbreviations with an associative array like this:
<?php
$stateArray = array(
"ALABAMA"=>"AL",
"ALASKA"=>"AK",
...
-1
votes
3answers
359 views
Sequential Looping through a Python Dictionary giving problems [duplicate]
Possible Duplicate:
In what order does python display dictionary keys?
There was this very weird Python question which I was trying to answer (on SO but looks like the author deleted it). ...
0
votes
0answers
240 views
Associative arrays passed to javascript as JSON , from a python view code (Django)
Okay
so here's my problem , I'm passing something like this to my templates :
return HttpResponse(simplejson.dumps({u"places": place_jsr, u"jobs": job_jsr, u"goods": good_jsr}), ...
1
vote
6answers
361 views
How to implement associative array (not dictionary) in Python?
I trying to print out a dictionary in Python:
Dictionary = {"Forename":"Paul","Surname":"Dinh"}
for Key,Value in Dictionary.iteritems():
print Key,"=",Value
Although the item "Forename" is listed ...
4
votes
4answers
197 views
What is the Python best practice concerning dicts vs objects for simple key-value storage?
After some time programming in Javascript I have grown a little fond of the duality there between objects and associative arrays (dictionaries):
//Javascript
var stuff = { a: 17, b: 42 };
stuff.a; ...
1
vote
3answers
1k views
Two dimensional associative array in Python
I have a set() with terms like 'A' 'B' 'C'. I want a 2-d associative array so that i can perform an operation like d['A']['B'] += 1 . What is the pythonic way of doing this, I was thinking a dicts of ...
4
votes
3answers
6k views
Python: Create associative array in a loop
I want to create an associative array with values read from a file. My code looks something like this, but its giving me an error saying i can't the indicies must be ints.
Thanks =]
for line in ...
3
votes
3answers
3k views
Python: Adding elements to an dict list or associative array
Im trying to add elements to a dict list (associative array), but every time it loops, the array overwrites the previous element. So i just end up with an array of size 1 with the last element read. I ...
2
votes
1answer
4k views
Django array or list output?
I'm pulling a set of image urls and their respective titles. I've tried creating a hash or associative array, but the data seems to overwrite so I only end up with the last item in the array.
For ...