Search Results

Search found 6 results on 1 pages for 'ordereddict'.

Page 1/1 | 1 

  • Which implementation of OrderedDict should be used in python2.6?

    - by Jorge Vargas
    As some of you may know in python2.7/3.2 we'll get OrderedDict with PEP372 however one of the reason the PEP existed was because everyone did their own implementation and they were all sightly incompatible. So which one of the 8 current implementations link text is backwards compatible with the 2.7 odict from python 2.7 in a way we can start using that now and depend on 2.7 in a couple of months?

    Read the article

  • Object directing to a property when accessed as an iterable

    - by ThE_JacO
    I'm trying to figure out if there's an elegant and concise way to have a class accessing one of its own properties when "used" as a dictionary, basically redirecting all the methods that'd be implemented in an ordered dictionary to one of its properties. Currently I'm inheriting from IterableUserDict and explicitly setting its data to another property, and it seems to be working, but I know that UserDict is considered sort of old, and I'm concerned I might be overlooking something. What I have: class ConnectionInterface(IterableUserDict): def __init__(self, hostObject): self._hostObject= hostObject self.ports= odict.OrderedDict() self.inputPorts= odict.OrderedDict() self.outputPorts= odict.OrderedDict() self.data= self.ports This way I expect the object to behave and respond (and be used) the way I mean it to, except I want to get a freebie ordered dictionary behaviour on its property "ports" when it's iterated, items are gotten by key, something is looked up ala if this in myObject, and so on. Any advice welcome, the above seems to be working fine, but I have an odd itch that I might be missing something. Thanks in advance.

    Read the article

  • Java's TreeSet equivalent in Python?

    - by viksit
    I recently came across some Java code that simply put some strings into a Java TreeSet, implemented a distance based comparator for it, and then made its merry way into the sunset to compute a given score to solve the given problem. My questions, Is there an equivalent data structure available for Python? The Java treeset looks basically to be an ordered dictionary that can use a comparator of some sort to achieve this ordering. I see there's a PEP for Py3K for an OrderedDict, but I'm using 2.6.x. There are a bunch of ordered dict implementations out there - anyone in particular that can be recommended? Thanks.

    Read the article

  • Adding a child node to a JSON node dynamically

    - by Sai
    I have to create a nested multi level json depending on the resultset that I get from MYSQL. I created a json object initially. Now I want to add child nodes to the already child nodes in the object. d = collections.OrderedDict() jsonobj = {"test": dict(updated_at="today", ID="ID", ads=[])} for rows1 in rs: jsonobj['list']["ads"].append(dict(unit = "1", type ="ad_type", id ="123", updated_at="today", x_id="111", x_name="test")) cur.execute("SELECT * from f_test") rs1 = cur.fetchall() for rows2 in rs1: propertiesObj = [] d["name"]="propName" d["type"]="TypeName" d["value"]="Value1" propertiesObj.append(d) jsonobj['play_list']["ads"].append() Here in the above line I want to add another child node to [play_list].[ads] which is a array list again. the output should look like the following [list].[ads].[preferences].

    Read the article

  • Stack and Hash joint

    - by Alexandru
    I'm trying to write a data structure which is a combination of Stack and HashSet with fast push/pop/membership (I'm looking for constant time operations). Think of Python's OrderedDict. I tried a few things and I came up with the following code: HashInt and SetInt. I need to add some documentation to the source, but basically I use a hash with linear probing to store indices in a vector of the keys. Since linear probing always puts the last element at the end of a continuous range of already filled cells, pop() can be implemented very easy without a sophisticated remove operation. I have the following problems: the data structure consumes a lot of memory (some improvement is obvious: stackKeys is larger than needed). some operations are slower than if I have used fastutil (eg: pop(), even push() in some scenarios). I tried rewriting the classes using fastutil and trove4j, but the overall speed of my application halved. What performance improvements would you suggest for my code? What open-source library/code do you know that I can try?

    Read the article

  • "import numpy" tries to load my own package

    - by Sebastian
    I have a python (2.7) project containing my own packages util and operator (and so forth). I read about relative imports, but perhaps I didn't understand. I have the following directory structure: top-dir/ util/__init__.py (empty) util/ua.py util/ub.py operator/__init__.py ... test/test1.py The test1.py file contains #!/usr/bin/env python2 from __future__ import absolute_import # removing this line dosn't change anything. It's default functionality in python2.7 I guess import numpy as np It's fine when I execute test1.py inside the test/ folder. But when I move to the top-dir/ the import numpy wants to include my own util package: Traceback (most recent call last): File "tests/laplace_2d_square.py", line 4, in <module> import numpy as np File "/usr/lib/python2.7/site-packages/numpy/__init__.py", line 137, in <module> import add_newdocs File "/usr/lib/python2.7/site-packages/numpy/add_newdocs.py", line 9, in <module> from numpy.lib import add_newdoc File "/usr/lib/python2.7/site-packages/numpy/lib/__init__.py", line 4, in <module> from type_check import * File "/usr/lib/python2.7/site-packages/numpy/lib/type_check.py", line 8, in <module> import numpy.core.numeric as _nx File "/usr/lib/python2.7/site-packages/numpy/core/__init__.py", line 45, in <module> from numpy.testing import Tester File "/usr/lib/python2.7/site-packages/numpy/testing/__init__.py", line 8, in <module> from unittest import TestCase File "/usr/lib/python2.7/unittest/__init__.py", line 58, in <module> from .result import TestResult File "/usr/lib/python2.7/unittest/result.py", line 9, in <module> from . import util File "/usr/lib/python2.7/unittest/util.py", line 2, in <module> from collections import namedtuple, OrderedDict File "/usr/lib/python2.7/collections.py", line 9, in <module> from operator import itemgetter as _itemgetter, eq as _eq ImportError: cannot import name itemgetter The troublesome line is either from . import util or perhaps from operator import itemgetter as _itemgetter, eq as _eq What can I do?

    Read the article

1