Clearing the Deque • Picturing Python’s `deque` data structure

2023-11-07 Thread dn via Python-list
. Instead, he’ll present a different perspective on what this data structure is, and how it differs from a list. The presentation will compare deques and lists in a visual manner, to help us understand why we may need a deque in certain situations. We’ll also explore some demonstration examples to

Re: Data structure for plotting monotonically expanding data set

2021-06-05 Thread Martin Di Paola
One way to go is using Pandas as it was mentioned before and Seaborn for plotting (built on top of matplotlib) I would approach this prototyping first with a single file and not with the 1000 files that you have. Using the code that you have for parsing, add the values to a Pandas DataFrame

Re: Data structure for plotting monotonically expanding data set

2021-06-04 Thread Chris Nyland
I agree with dn. While you could scrape the text files each time you want to display a user from a design perspective it makes more sense to use a database to store the data. This doesn't mean that you need to get rid of the text files or change the format that they are written to but instead that

Re: Data structure for plotting monotonically expanding data set

2021-05-27 Thread dn via Python-list
On 27/05/2021 21.28, Loris Bennett wrote: > Hi, > > I currently a have around 3 years' worth of files like > > home.20210527 > home.20210526 > home.20210525 > ... > > so around 1000 files, each of which contains information about data > usage in lines like > > namekb > alice 1

Re: Data structure for plotting monotonically expanding data set

2021-05-27 Thread Peter J. Holzer
On 2021-05-27 11:28:11 +0200, Loris Bennett wrote: > I currently a have around 3 years' worth of files like > > home.20210527 > home.20210526 > home.20210525 > ... > > so around 1000 files, each of which contains information about data > usage in lines like > > namekb > alice 1

Data structure for plotting monotonically expanding data set

2021-05-27 Thread Loris Bennett
Hi, I currently a have around 3 years' worth of files like home.20210527 home.20210526 home.20210525 ... so around 1000 files, each of which contains information about data usage in lines like namekb alice 123 bob 4 ... zebedee 999 (there are actually more colum

Re: Data structure for plotting monotonically expanding data set

2021-05-27 Thread Edmondo Giovannozzi
Il giorno giovedì 27 maggio 2021 alle 11:28:31 UTC+2 Loris Bennett ha scritto: > Hi, > > I currently a have around 3 years' worth of files like > > home.20210527 > home.20210526 > home.20210525 > ... > > so around 1000 files, each of which contains information about data > usage in lines

Re: Help to understand the data structure

2019-09-27 Thread Mohan L
Hi All, Please ignore it, I was able to figure out it. for dev in devlist: print (dev.name, dev.id) -- Thanks & Regards Mohan L On Fri, Sep 27, 2019 at 8:41 PM Mohan L wrote: > Hi All, > > I am using get_devices_list method from this module: > https://github.com/Tufin/pytos/blob/mast

Help to understand the data structure

2019-09-27 Thread Mohan L
Hi All, I am using get_devices_list method from this module: https://github.com/Tufin/pytos/blob/master/pytos/securetrack/helpers.py. Here is my two like code and output looks like: https://pastebin.com/K9KBeqYL I am not able to manage to further loop the data to print below output: devicename

Re: Data-structure for multiway associativity in Python

2018-01-28 Thread Steven D'Aprano
On Sun, 28 Jan 2018 14:48:02 -0800, qrious wrote: > First list = { 1, 2, 3} > Second list = { 4, 5, 6} > Third list = { 7, 8, 9} > > If I pass 9 as the argument, the return value of the function would be > {7, 8}. subsets = [{1, 2, 3}, {4, 5, 6}, {7, 8, 9}] data = {} for subset in subsets:

Re: Data-structure for multiway associativity in Python

2018-01-28 Thread qrious
iway tree > that avoids having to search all of the thousands of lists before giving > up. Which brings us to the Subject line of this thread. Without any relationship among the members, could we solve this using clever data structure? > > Are searches going to typically hit the

Re: Data-structure for multiway associativity in Python

2018-01-28 Thread Steven D'Aprano
On Sat, 27 Jan 2018 10:01:47 -0800, qrious wrote: > I need a data structure and a corresponding (hopefully fast) mechanism > associated with it to do the following. While I am looking for the > concept first, my preference for implementation of this will be in > Python. > > [c1

Re: Data-structure for multiway associativity in Python

2018-01-27 Thread MRAB
On 2018-01-27 18:01, qrious wrote: I need a data structure and a corresponding (hopefully fast) mechanism associated with it to do the following. While I am looking for the concept first, my preference for implementation of this will be in Python. [c1, c2,..., cn] is a list of strings (for

Re: Data-structure for multiway associativity in Python

2018-01-27 Thread Dan Stromberg
27, 2018 at 10:33 AM, Dennis Lee Bieber wrote: > On Sat, 27 Jan 2018 10:01:47 -0800 (PST), qrious > declaimed the following: > >> >> >>I need a data structure and a corresponding (hopefully fast) mechanism >>associated with it to do the following. While I a

Data-structure for multiway associativity in Python

2018-01-27 Thread qrious
I need a data structure and a corresponding (hopefully fast) mechanism associated with it to do the following. While I am looking for the concept first, my preference for implementation of this will be in Python. [c1, c2,..., cn] is a list of strings (for my own implementation, but could be

Re: data structure

2017-06-15 Thread Andrew Zyman
Paul Thank you. In my case all "members" of a data structure are classes (except of the id). I showed the classes to highlight the requirement to access their methods as vs simple data types. I think dict of lists should work. Ideally , I hoped to access by name ( vs index), but list w

Re: data structure

2017-06-15 Thread Paul Barry
Hi Andrew. You start by talking about a data structure, then show code that uses "class". Not everything in Python needs to be in a class. I'd look at using a simple Dictionary of lists, indexed on your ID. A list can contain anything, so you can add your objects in there dynami

Re: data structure

2017-06-14 Thread Frank Millman
"Andrew Zyman" wrote in message news:caprckxktozonlak8asizonkypd9y_p25fr2rkfkozxoa4bc...@mail.gmail.com... Hello, i wonder what would be a proper data structure for something with the following characteristics: id - number, obj[a..c] - objects of various classes the idea is to

data structure

2017-06-14 Thread Andrew Zyman
Hello, i wonder what would be a proper data structure for something with the following characteristics: id - number, obj[a..c] - objects of various classes the idea is to be able to update certain fields of these objects initially getting access to the record by ID something like this ( not

Help needed in mapping Magento 1.x/PHP data structure into Python equivalent for suds

2016-05-31 Thread Parul M
Hello All, I need assistance in calling Magento 1.x SOAP API's using Python suds library. How to map the *PHP data structure array(array(k1=>v1, k2=>v2,.)) in terms of python suds*??? The exposed SOAP API syntax for creating a new customer in magento: ult = $client->

RE: What sort of data structure to use?

2015-06-03 Thread David Aldrich
; Sent: 03 June 2015 11:59 > To: python-list@python.org > Subject: Re: What sort of data structure to use? > > David Aldrich wrote: > > > Hi > > > > I have written a Python utility that performs a certain activity on > > some predefined sets of files. Here

Re: What sort of data structure to use?

2015-06-03 Thread Peter Otten
) > > I want to add more file sets, so I really want to add the sets to a list > and iterate over the list, calling myFunc1 & myFunc2 for each item. > > My question is: what sort of data structure could I use to organise this, > given that I want to associate a set

Re: What sort of data structure to use?

2015-06-03 Thread David Palao
nc2(pathB, fileListB) > > > > I want to add more file sets, so I really want to add the sets to a list and > iterate over the list, calling myFunc1 & myFunc2 for each item. > > > > My question is: what sort of data structure could I use to organise this, > given that

Re: What sort of data structure to use?

2015-06-03 Thread Cameron Simpson
d iterate over the list, calling myFunc1 & myFunc2 for each item. My question is: what sort of data structure could I use to organise this, given that I want to associate a set of files with each path and that, for each set, there is an arbitrary number of files? Based on your description

Re: What sort of data structure to use?

2015-06-03 Thread David Palao
nc2(pathB, fileListB) > > > > I want to add more file sets, so I really want to add the sets to a list and > iterate over the list, calling myFunc1 & myFunc2 for each item. > > > > My question is: what sort of data structure could I use to organise this, > given that

What sort of data structure to use?

2015-06-03 Thread David Aldrich
B = ['fileB1.txt', 'fileB2.txt', 'fileB3.txt'] myFunc1(pathA, fileListA) myFunc2(pathA, fileListA) myFunc1(pathB, fileListB) myFunc2(pathB, fileListB) I want to add more file sets, so I really want to add the sets to a list and iterate over the list, calling myFunc1

Re: Inner workings of this Python feature: Can a Python data structure reference itself?

2015-05-03 Thread vasudevram
On Sunday, May 3, 2015 at 6:38:28 PM UTC+5:30, Chris Angelico wrote: > On Sun, May 3, 2015 at 10:59 PM, vasudevram wrote: > > Re. statement of fact vs. hypotheses. While I'm not sure of your exact > > meaning in that paragraph, I understand the concept, and yes, I was not > > clear enough in phr

Re: Inner workings of this Python feature: Can a Python data structure reference itself?

2015-05-03 Thread vasudevram
On Sunday, May 3, 2015 at 6:30:16 PM UTC+5:30, vasudevram wrote: > On Sunday, May 3, 2015 at 4:48:11 AM UTC+5:30, Terry Reedy wrote: > > On 5/2/2015 4:02 PM, vasudevram wrote: > > > Hi group, > > > > > > Please refer to this blog post about code showing that

Re: Inner workings of this Python feature: Can a Python data structure reference itself?

2015-05-03 Thread Chris Angelico
On Sun, May 3, 2015 at 10:59 PM, vasudevram wrote: > Re. statement of fact vs. hypotheses. While I'm not sure of your exact > meaning in that paragraph, I understand the concept, and yes, I was not clear > enough in phrasing that part. It should have read like something along these > lines: > >

Re: Inner workings of this Python feature: Can a Python data structure reference itself?

2015-05-03 Thread vasudevram
On Sunday, May 3, 2015 at 4:48:11 AM UTC+5:30, Terry Reedy wrote: > On 5/2/2015 4:02 PM, vasudevram wrote: > > Hi group, > > > > Please refer to this blog post about code showing that a Python data > > structure can be self-referential: > > > > http://jug

Re: Inner workings of this Python feature: Can a Python data structure reference itself?

2015-05-03 Thread Steven D'Aprano
On Sun, 3 May 2015 09:17 am, Terry Reedy wrote: > I believe that there was a time when printing a recursive structure hit > the recursion limit like your flatten did. But I will not reload 1.5 to > check. No, that was already fixed by 1.5: [steve@ando ~]$ python1.5 Python 1.5.2 (#1, Aug 27 2012,

Re: Inner workings of this Python feature: Can a Python data structure reference itself?

2015-05-03 Thread vasudevram
On Sunday, May 3, 2015 at 1:32:14 AM UTC+5:30, vasudevram wrote: > Hi group, > > Please refer to this blog post about code showing that a Python data > structure can be self-referential: > > http://jugad2.blogspot.in/2015/05/can-python-data-structure-reference.html >

Re: Inner workings of this Python feature: Can a Python data structure reference itself?

2015-05-02 Thread Chris Angelico
On Sun, May 3, 2015 at 2:43 PM, Ian Kelly wrote: > On Sat, May 2, 2015 at 2:17 PM, Tim Chase > wrote: >> If you know that you're creating such cyclical structures, it's best >> to manually unlink them before freeing them: >> >> lst = [] >> lst.append(lst) # create the cycle >> lst[:] = []

Re: Inner workings of this Python feature: Can a Python data structure reference itself?

2015-05-02 Thread Ian Kelly
On Sat, May 2, 2015 at 2:17 PM, Tim Chase wrote: > If you know that you're creating such cyclical structures, it's best > to manually unlink them before freeing them: > > lst = [] > lst.append(lst) # create the cycle > lst[:] = [] # break the cycle > # or lst.remove(lst) # though this ta

Re: Inner workings of this Python feature: Can a Python data structure reference itself?

2015-05-02 Thread Ian Kelly
On Sat, May 2, 2015 at 7:57 PM, Tim Chase wrote: > So it sounds like you have to request such a mark-and-sweep from > the gc module. You *can* request it. But as long as it hasn't been explicitly disabled (by calling gc.disable()), the mark-and-sweep garbage collection will also run automatically

Re: Inner workings of this Python feature: Can a Python data structure reference itself?

2015-05-02 Thread Tim Chase
On 2015-05-02 23:06, Cecil Westerhof wrote: > Op Saturday 2 May 2015 22:17 CEST schreef Tim Chase: >> This creates a cycle, then makes it unreachable, but the list is >> still referenced by itself, so the reference count never drops to >> zero (where it would get GC'd), and thus that item lingers a

Re: Inner workings of this Python feature: Can a Python data structure reference itself?

2015-05-02 Thread Terry Reedy
On 5/2/2015 4:02 PM, vasudevram wrote: Hi group, Please refer to this blog post about code showing that a Python data structure can be self-referential: http://jugad2.blogspot.in/2015/05/can-python-data-structure-reference.html Gotten a couple of comments on it already, but interested in

Re: Inner workings of this Python feature: Can a Python data structure reference itself?

2015-05-02 Thread MRAB
On 2015-05-02 22:06, Cecil Westerhof wrote: Op Saturday 2 May 2015 22:17 CEST schreef Tim Chase: [dangit, had Control down when I hit and it sent prematurely] On 2015-05-02 13:02, vasudevram wrote: http://jugad2.blogspot.in/2015/05/can-python-data-structure-reference.html https

Re: Inner workings of this Python feature: Can a Python data structure reference itself?

2015-05-02 Thread Cecil Westerhof
Op Saturday 2 May 2015 22:17 CEST schreef Tim Chase: > [dangit, had Control down when I hit and it sent > prematurely] > > On 2015-05-02 13:02, vasudevram wrote: >> http://jugad2.blogspot.in/2015/05/can-python-data-structure-reference.html >> >> https://docs.python.

Re: Inner workings of this Python feature: Can a Python data structure reference itself?

2015-05-02 Thread vasudevram
On Sunday, May 3, 2015 at 1:47:04 AM UTC+5:30, Tim Chase wrote: > [dangit, had Control down when I hit and it sent prematurely] > > On 2015-05-02 13:02, vasudevram wrote: > > http://jugad2.blogspot.in/2015/05/can-python-data-structure-reference.html > > > > https://

Re: Inner workings of this Python feature: Can a Python data structure reference itself?

2015-05-02 Thread Tim Chase
On 2015-05-02 13:02, vasudevram wrote: > Hi group, > > Please refer to this blog post about code showing that a Python > data structure can be self-referential: > > http://jugad2.blogspot.in/2015/05/can-python-data-structure-reference.html > > Gotten a couple of com

Re: Inner workings of this Python feature: Can a Python data structure reference itself?

2015-05-02 Thread Tim Chase
[dangit, had Control down when I hit and it sent prematurely] On 2015-05-02 13:02, vasudevram wrote: > http://jugad2.blogspot.in/2015/05/can-python-data-structure-reference.html > > https://docs.python.org/2/reference/datamodel.html > > and saw this excerpt: > > [ CPython

Inner workings of this Python feature: Can a Python data structure reference itself?

2015-05-02 Thread vasudevram
Hi group, Please refer to this blog post about code showing that a Python data structure can be self-referential: http://jugad2.blogspot.in/2015/05/can-python-data-structure-reference.html Gotten a couple of comments on it already, but interested in hearing thoughts of Python core dev team

Re: trouble building data structure

2014-09-29 Thread Ian Kelly
On Mon, Sep 29, 2014 at 7:52 AM, Steven D'Aprano wrote: > Whether you prefer to use setdefault, or a defaultdict, is a matter of > taste. There is potentially a significant difference in performance -- with setdefault, the subordinate data structure is created on every call to be

Re: trouble building data structure

2014-09-29 Thread Steven D'Aprano
e 45, in > file_data[ md5sum ][ inode ] = { 'path' : path, 'size' : size, } > KeyError: '91b152ce64af8af91dfe275575a20489' > > what is the pythonic way to build my "file_data" data structure above that > has the above structure? Others have suggested usin

Re: trouble building data structure

2014-09-28 Thread Ned Batchelder
} KeyError: '91b152ce64af8af91dfe275575a20489' what is the pythonic way to build my "file_data" data structure above that has the above structure? If you want file_data to be a dictionary of dictionaries, use a defaultdict: file_data = collections.defaultdict(dict) Th

Re: trouble building data structure

2014-09-28 Thread Chris Angelico
On Mon, Sep 29, 2014 at 10:04 AM, David Alban wrote: > file_data = {} > > [... as i loop through lines in the file ...] > > file_data[ md5sum ][ inode ] = { 'path' : path, 'size' : size, } > > what is the pythonic way to build my &q

trouble building data structure

2014-09-28 Thread David Alban
ce64af8af91dfe275575a20489' what is the pythonic way to build my "file_data" data structure above that has the above structure? on http://en.wikipedia.org/wiki/Autovivification there is a section on how to do autovivification in python, but i want to learn how a python programmer would

Re: which data structure to use?

2014-01-22 Thread Robert Voigtländer
> Unlikely. Are you sure that .heap and .lookup contents are still in sync > with your modification? No it's not. Atfer having read about heapq it's clear why. Thanks for the hint. > allows you to delete random nodes, but the lowest() method will slow down as > it has to iterate over all dict v

Re: which data structure to use?

2014-01-21 Thread Peter Otten
e you sure that .heap and .lookup contents are still in sync with your modification? > Now I go on with trying to understand it. The pop() method as posted can only remove the "lowest" node. If contrary to your initial spec > 2. find the object with the lowest Node.f attri

Re: which data structure to use?

2014-01-21 Thread Mark Lawrence
On 21/01/2014 13:43, Robert Voigtländer wrote: [double spaced google disease snipped] I'm pleased to see the regular contributors helping out as usual. In response would you please be kind enough to read and action this https://wiki.python.org/moin/GoogleGroupsPython to prevent us seeing the

Re: which data structure to use?

2014-01-21 Thread Robert Voigtländer
> > > def pop(self): > > > f, node = heapq.heappop() > > > del lookup[node.pos] > > > return node > > That should be > > > def pop(self): > > > f, node = heapq.heappop(self.heap) > > del self.lookup[node.pos] > > return node > > Hi Peter,

Re: which data structure to use?

2014-01-21 Thread Robert Voigtländer
Am Dienstag, 21. Januar 2014 15:19:54 UTC+1 schrieb Peter Otten: > Peter Otten wrote: > > > > > def pop(self): > > > f, node = heapq.heappop() > > > del lookup[node.pos] > > > return node > > > > That should be > > > > def pop(self): > > f, node

Re: which data structure to use?

2014-01-21 Thread Peter Otten
Peter Otten wrote: > def pop(self): > f, node = heapq.heappop() > del lookup[node.pos] > return node That should be def pop(self): f, node = heapq.heappop(self.heap) del self.lookup[node.pos] return node -- https://mail.python.org/mailma

Re: which data structure to use?

2014-01-21 Thread Peter Otten
Robert Voigtländer wrote: > >> On Tue, Jan 21, 2014 at 03:17:43AM -0800, Robert Voigtl�nder wrote: >> > >> > I have objects like this: >> >> > >> >> > class Node(object): >> >> > def __init__(self, pos, parent, g , h): >> >> > self.pos = pos >> >> > self.parent = par

Re: which data structure to use?

2014-01-21 Thread Oscar Benjamin
): return min(opendict.values(), key=lambda x: x.f) def deleteItemWithPos(pos): del opendict[pos] nodes = [ Node((1,1),None,1,5), Node((1,2),(1,1),4,6), Node((1,3),(1,2),9,10), ] opendict = {} for node in nodes: opendict[node.pos] = node for item in opendict.values(): print item.pos, item.f print isinlist((1,1)) print isinlist((1,5)) nextNode = lowestF() print nextNode.pos, nextNode.f The above is more efficient and simpler. It is still O(N) for the lowestF() function. Changing data structure could make that more efficient. Oscar -- https://mail.python.org/mailman/listinfo/python-list

Re: which data structure to use?

2014-01-21 Thread Robert Voigtländer
Am Dienstag, 21. Januar 2014 14:38:34 UTC+1 schrieb Robert Voigtländer: > > On Tue, Jan 21, 2014 at 03:17:43AM -0800, Robert Voigtl�nder wrote: > > > > > > > > > I have objects like this: > > > > > > > > > > > > > > class Node(object): > > > > > > > def __init__(self, pos, par

Re: which data structure to use?

2014-01-21 Thread Robert Voigtländer
> On Tue, Jan 21, 2014 at 03:17:43AM -0800, Robert Voigtl�nder wrote: > > > I have objects like this: > > > > > > class Node(object): > > > def __init__(self, pos, parent, g , h): > > > self.pos = pos > > > self.parent = parent > > > self.g = g > > >

Re: which data structure to use?

2014-01-21 Thread Oscar Benjamin
On Tue, Jan 21, 2014 at 03:17:43AM -0800, Robert Voigtländer wrote: > Hi, > > which would be the best data structure to use for the following case? > > I have objects like this: > > class Node(object): > def __init__(self, pos, parent, g , h):

Re: which data structure to use?

2014-01-21 Thread Ben Finney
Robert Voigtländer writes: > which would be the best data structure to use for the following case? First up, I want to compliment you on asking exactly the right question. Getting the data structure right or wrong can often shape the solution dramatically. > I have objects like this: >

Re: which data structure to use?

2014-01-21 Thread Chris Angelico
On Tue, Jan 21, 2014 at 10:17 PM, Robert Voigtländer wrote: > 1. check if a specific item - identified by Node.pos - is in the list. > 2. find the object with the lowest Node.f attribute and update or remove it Are both those values constant once the Node is added? If so, the easiest way would be

which data structure to use?

2014-01-21 Thread Robert Voigtländer
Hi, which would be the best data structure to use for the following case? I have objects like this: class Node(object): def __init__(self, pos, parent, g , h): self.pos = pos self.parent = parent self.g = g self.h = h self.f = g+h I need to

RE: Data structure question

2013-11-17 Thread Joseph L. Casale
> How about two dictionaries, each containing the same tuples for > values? If you create a tuple first, then add it to both dicts, you > won't have any space-wasting duplicates. Thanks guys. -- https://mail.python.org/mailman/listinfo/python-list

Re: Data structure question

2013-11-17 Thread Dave Angel
On Mon, 18 Nov 2013 02:03:38 +, "Joseph L. Casale" wrote: I have a need for a script to hold several tuples with three values, two text strings and a lambda. I need to index the tuple based on either of the two strings. Normally a database would be ideal but for a self-contained script

RE: Data structure question

2013-11-17 Thread Joseph L. Casale
> Not entirely sure I understand you, can you post an example? > > If what you mean is that you need to locate the function (lambda) when > you know its corresponding strings, a dict will suit you just fine. > Either maintain two dicts for the two separate strings (eg if they're > "name" and "loca

Re: Data structure question

2013-11-17 Thread Ned Batchelder
On Sunday, November 17, 2013 9:03:38 PM UTC-5, Joseph L. Casale wrote: > I have a need for a script to hold several tuples with three values, two text > strings and a lambda. I need to index the tuple based on either of the two > strings. Normally a database would be ideal but for a self-contained

Re: Data structure question

2013-11-17 Thread Chris Angelico
On Mon, Nov 18, 2013 at 1:03 PM, Joseph L. Casale wrote: > I have a need for a script to hold several tuples with three values, two text > strings and a lambda. I need to index the tuple based on either of the two > strings. Normally a database would be ideal but for a self-contained script > that

Re: Data structure question

2013-11-17 Thread Tim Chase
On 2013-11-18 02:03, Joseph L. Casale wrote: > I have a need for a script to hold several tuples with three > values, two text strings and a lambda. I need to index the tuple > based on either of the two strings. Normally a database would be > ideal but for a self-contained script that's a bit much

Data structure question

2013-11-17 Thread Joseph L. Casale
I have a need for a script to hold several tuples with three values, two text strings and a lambda. I need to index the tuple based on either of the two strings. Normally a database would be ideal but for a self-contained script that's a bit much. Before I re-invent the wheel, are there any built-

Re: need data structure to for test results analysis

2013-07-06 Thread Joshua Landau
On 6 July 2013 15:58, wrote: > I have a python program that reads test result information from SQL and > creates the following data that I want to capture in a data structure so it > can be prioritized appropriately :- > > test_name new fail

need data structure to for test results analysis

2013-07-06 Thread terry433iid
I have a python program that reads test result information from SQL and creates the following data that I want to capture in a data structure so it can be prioritized appropriately :- test_name new fail P1 test_name known fail (but no bug logged

Re: fastest data structure for retrieving objects identified by (x,y) tuple?

2012-10-04 Thread Steven D'Aprano
On Thu, 04 Oct 2012 18:11:28 +0200, Thomas Rachel wrote: > Am 04.10.2012 03:58 schrieb Steven D'Aprano: >> alist = [[None]*2400 for i in range(2400)] from random import randrange >> for i in range(1000): >> x = randrange(2400) >> y = randrange(2400) >> adict[(x, y)] = "something" >>

Re: fastest data structure for retrieving objects identified by (x, y) tuple?

2012-10-04 Thread Thomas Rachel
Am 04.10.2012 03:58 schrieb Steven D'Aprano: alist = [[None]*2400 for i in range(2400)] from random import randrange for i in range(1000): x = randrange(2400) y = randrange(2400) adict[(x, y)] = "something" alist[x][y] = "something" The actual sizes printed will depend on h

Re: fastest data structure for retrieving objects identified by (x, y) tuple?

2012-10-04 Thread Steven D'Aprano
On Thu, 04 Oct 2012 08:21:13 -0400, Benjamin Jessup wrote: > On 10/4/2012 12:20 AM, python-list-requ...@python.org wrote: >> How do you know that? >> >> No offence, but if you can't even work out whether lookups in a dict or >> a list are faster, I can't imagine why you think you can intuit what >

Re: fastest data structure for retrieving objects identified by (x, y) tuple?

2012-10-04 Thread Benjamin Jessup
On 10/4/2012 12:20 AM, python-list-requ...@python.org wrote: How do you know that? No offence, but if you can't even work out whether lookups in a dict or a list are faster, I can't imagine why you think you can intuit what the fastest way to retrieve the nearest neighbours would be. Whats wro

Re: fastest data structure for retrieving objects identified by (x, y) tuple?

2012-10-04 Thread Oscar Benjamin
On Oct 4, 2012 3:02 AM, "Steven D'Aprano" < steve+comp.lang.pyt...@pearwood.info> wrote: > # populate a random matrix using both dict and list > adict = {} > alist = [[None]*2400 for i in range(2400)] > from random import randrange > for i in range(1000): > x = randrange(2400) > y = randran

Re: fastest data structure for retrieving objects identified by (x,y) tuple?

2012-10-03 Thread Steven D'Aprano
On Thu, 04 Oct 2012 01:58:16 +, Steven D'Aprano wrote: > adict: 24712 > alist: 23127324 [...] > So in this situation, a list of lists uses about 100 times > more memory than a dict, but look-ups are about 6% faster. Correction: about 1000 times more memory. Sorry for the typo. -- Steven -

Re: fastest data structure for retrieving objects identified by (x,y) tuple?

2012-10-03 Thread Steven D'Aprano
On Wed, 03 Oct 2012 18:30:24 -0400, Benjamin Jessup wrote: > I have a group of objects identified by unique (x,y) pairs and I want to > find out an object's "neighbors" in a matrix of size 2400 x 2400. [...] > There is either a neighbor, or a null value. I always know the (x,y) > pair to check the

Re: fastest data structure for retrieving objects identified by (x, y) tuple?

2012-10-03 Thread Joshua Landau
On 3 October 2012 23:30, Benjamin Jessup wrote: > I have a group of objects identified by unique (x,y) pairs and I want to > find out an object's "neighbors" in a matrix of size 2400 x 2400. ># >#obj# # # ># ># # #obj# 3 x 3 Exa

fastest data structure for retrieving objects identified by (x,y) tuple?

2012-10-03 Thread Benjamin Jessup
I have a group of objects identified by unique (x,y) pairs and I want to find out an object's "neighbors" in a matrix of size 2400 x 2400. # #obj# # # # # # #obj# 3 x 3 Example # # # # # ##

Re: Best data structure for DFS on large graphs

2012-07-03 Thread Dan Stromberg
On Tue, Jul 3, 2012 at 3:08 PM, Miheer Dewaskar wrote: > On Tue, Jul 3, 2012 at 8:10 PM, Tim Chase > wrote: > I want it to be a generic Game solver.So the number of states depends > on the game. > Keep in mind that it would probably be a generic game solver for games that have simple board evalu

Re: Best data structure for DFS on large graphs

2012-07-03 Thread Miheer Dewaskar
On Tue, Jul 3, 2012 at 8:10 PM, Tim Chase wrote: > On 07/03/12 08:39, Miheer Dewaskar wrote: >> On Tue, Jul 3, 2012 at 4:53 PM, Stefan Behnel wrote: >>> >>> Miheer Dewaskar, 03.07.2012 13:11: I am not sure,but if there are large number of states Dictionaries wont help much right? >>> >>

Re: Best data structure for DFS on large graphs

2012-07-03 Thread Tim Chase
On 07/03/12 08:39, Miheer Dewaskar wrote: > On Tue, Jul 3, 2012 at 4:53 PM, Stefan Behnel wrote: >> >> Miheer Dewaskar, 03.07.2012 13:11: >>> I am not sure,but if there are large number of states Dictionaries wont >>> help much right? >> >> Dicts are fast for lookup, not for searching. >> > What d

Re: Best data structure for DFS on large graphs

2012-07-03 Thread Miheer Dewaskar
ing in the context of Dicts? > > Anyway, does python have a built-in BST like data-structure ? > > It has lists and bisect: > > http://docs.python.org/library/bisect.html But insertion and deletion in a list is o(n): http://wiki.python.org/moin/TimeComplexity/#list -- Mihee

Re: Best data structure for DFS on large graphs

2012-07-03 Thread Stefan Behnel
Miheer Dewaskar, 03.07.2012 13:11: > I want to make a combinatorial game solver in python.The algorithm is to > perform Depth First Search (DFS) on the states of the game. > For DFS I,would need to keep a record of the visited states.What is the > best data structure for it,keeping

Best data structure for DFS on large graphs

2012-07-03 Thread Miheer Dewaskar
I want to make a combinatorial game solver in python.The algorithm is to perform Depth First Search (DFS) on the states of the game. For DFS I,would need to keep a record of the visited states.What is the best data structure for it,keeping in mind that the number of states could be large? I was

Re: Good data structure for finding date intervals including a given date

2012-05-21 Thread Daniel Stutzbach
On Wed, May 16, 2012 at 5:38 AM, Jean-Daniel wrote: > On Sun, May 13, 2012 at 2:29 PM, Alec Taylor > wrote: > > There is an ordered dict type since Python 3.1[1] and Python 2.7.3[2]. > > Ordered dict are useful, but they only remember the ordered in which > they were added, you can not order them

Re: Good data structure for finding date intervals including a given date

2012-05-16 Thread Jean-Daniel
On Sun, May 13, 2012 at 2:29 PM, Alec Taylor wrote: > There is an ordered dict type since Python 3.1[1] and Python 2.7.3[2]. Ordered dict are useful, but they only remember the ordered in which they were added, you can not order them a on key. Thanks for the links. > > If you are looking for th

Re: Good data structure for finding date intervals including a given date

2012-05-14 Thread Christian Heimes
O(n)). > > Do you know the best way to do this in Python with the stdlib? > > A variant of the red black trees can do the job quickly [1], is this a > good enough use case to discuss the inclusion of a red black tree > implementation in the stdlib? A more general data structure fo

Re: Good data structure for finding date intervals including a given date

2012-05-14 Thread Karl Knechtel
On Sat, May 12, 2012 at 10:18 AM, Jean-Daniel wrote: >> Since you say "intervals" in plural here, I assume that they can overlap? > > Yes, > > For instance, there are the following intervals : > [[1, 10], > [4, 7], > [6, 15], > [11, 17]] > > asking for the intervals including  5, the returned valu

Re: Good data structure for finding date intervals including a given date

2012-05-13 Thread Emile van Sebille
On 5/12/2012 5:17 AM Jean-Daniel said... Hello, I have a long list of n date intervals that gets added or suppressed intervals regularly. I am looking for a fast way to find the intervals containing a given date, without having to check all intervals (less than O(n)). ISTM the fastest way is t

Re: Good data structure for finding date intervals including a given date

2012-05-13 Thread Arnaud Delobelle
On 13 May 2012 13:29, Alec Taylor wrote: > There is an ordered dict type since Python 3.1[1] and Python 2.7.3[2]. I don't think that'll help the OP. Python's OrderedDict keeps track of the order in which the keys were inserted into the dictionary (a bit like a list), it doesn't keep the keys sor

Re: Good data structure for finding date intervals including a given date

2012-05-13 Thread Alec Taylor
There is an ordered dict type since Python 3.1[1] and Python 2.7.3[2]. If you are looking for the best possible self-sorting structure for searching, then perhaps you are looking for what's outlined in the 2002 article by Han & Thorup: Integer Sorting in O(n sqrt(log log n)) Expected Time and Line

Re: Good data structure for finding date intervals including a given date

2012-05-12 Thread Neal Becker
Probably boost ITL (Interval Template Library) would serve as a good example. I noticed recently someone created an interface for python. -- http://mail.python.org/mailman/listinfo/python-list

Re: Good data structure for finding date intervals including a given date

2012-05-12 Thread Jean-Daniel
> Since you say "intervals" in plural here, I assume that they can overlap? Yes, For instance, there are the following intervals : [[1, 10], [4, 7], [6, 15], [11, 17]] asking for the intervals including 5, the returned value should be [[1, 10], [4, 7]] The idea here to make it fast is to have

Re: Good data structure for finding date intervals including a given date

2012-05-12 Thread Mark Lawrence
On 12/05/2012 13:17, Jean-Daniel wrote: Hello, Do you know the best way to do this in Python with the stdlib? Sorry, not part of the stdlib but search for red black tree here http://pypi.python.org/pypi. While you're there also take a look at the blist package. -- Cheers. Mark Lawrence

Re: Good data structure for finding date intervals including a given date

2012-05-12 Thread Karl Knechtel
On Sat, May 12, 2012 at 8:17 AM, Jean-Daniel wrote: > I am looking for a fast way to find the intervals > containing a given date, without having to check all intervals (less > than O(n)). Since you say "intervals" in plural here, I assume that they can overlap? -- ~Zahlman {:> -- http://mail.

Good data structure for finding date intervals including a given date

2012-05-12 Thread Jean-Daniel
Hello, I have a long list of n date intervals that gets added or suppressed intervals regularly. I am looking for a fast way to find the intervals containing a given date, without having to check all intervals (less than O(n)). Do you know the best way to do this in Python with the stdlib? A var

Re: red-black tree data structure

2012-04-11 Thread Dan Stromberg
Bringing this back to Python a bit: http://newcenturycomputers.net/projects/rbtree.html http://pypi.python.org/pypi/bintrees/0.3.0 http://pypi.python.org/pypi/treap/0.995 Red-Black trees are supposed to be slower than treaps on average, but they're also supposed to have a lower standard deviation

Re: red-black tree data structure

2012-04-11 Thread Jabba Laci
Hi, Thanks for the answer. I copy the solution here: According to wikipedia: "The original structure was invented in 1972 by Rudolf Bayer and named "symmetric binary B-tree," but acquired its modern name in a paper in 1978 by Leonidas J. Guibas and Robert Sedgewick." Answer from Professor Guidas

  1   2   3   4   >