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

2012-05-21 Thread Daniel Stutzbach
t they might be useful parts of an efficient solution. More information: http://pypi.python.org/pypi/blist http://stutzbachenterprises.com/blist/ -- Daniel Stutzbach -- http://mail.python.org/mailman/listinfo/python-list

Re: how to sort a hash list without generating a new object?

2011-08-03 Thread Daniel Stutzbach
different performance characteristics, and a sorteddict works just like a dict but keeps the keys sorted. -- Daniel Stutzbach -- http://mail.python.org/mailman/listinfo/python-list

Re: blist question

2011-07-07 Thread Daniel Stutzbach
d into Python source code? > Seems unlikely. -- Daniel Stutzbach -- http://mail.python.org/mailman/listinfo/python-list

Re: ANN: blist 1.2.0

2010-07-23 Thread Daniel Stutzbach
On Wed, Jul 21, 2010 at 9:47 AM, Daniel Stutzbach < dan...@stutzbachenterprises.com> wrote: > What's new? > --- > > - blist.sort() is now *substantially* faster than list.sort() when using > int or float keys (O(n) vs. O(n log n)) > - The sortedset, sortedli

Re: ANN: blist 1.2.0

2010-07-22 Thread Daniel Stutzbach
Thank you for the thoughts. I appreciate them! -- Daniel Stutzbach, Ph.D. President, Stutzbach Enterprises, LLC <http://stutzbachenterprises.com> -- http://mail.python.org/mailman/listinfo/python-list

Re: ANN: blist 1.2.0

2010-07-22 Thread Daniel Stutzbach
at's a good point. It's tempting to add an undocumented parameter to blist.sort that selects the sorting algorithm to use, to make it make it easier to test multiple algorithms. There are probably several different ways to achieve a similar effect. Do you mind if we table that discussion unt

Re: ANN: blist 1.2.0

2010-07-21 Thread Daniel Stutzbach
and resorts, list.sort will skip the sorted part, > sort the additions, and merge them back in. Radix sort ignores pre-existing > order. So either a lot of comparitive profiling would be needed for > auto-selection of sort method, or it should be user selectable. > I'v

Re: ANN: blist 1.2.0

2010-07-21 Thread Daniel Stutzbach
that I need to take care of. After that I plan to work on porting my sort optimizations back to the standard list type. Here's a performance comparison of sorting with blist versus 3.1's list: http://stutzbachenterprises.com/performance-blist/sort-random-list -- Daniel Stutzbach, Ph.D. Pres

ANN: blist 1.2.0

2010-07-21 Thread Daniel Stutzbach
mentation: http://stutzbachenterprises.com/blist/ - Download: http://pypi.python.org/pypi/blist/ - Source repository: http://github.com/DanielStutzbach/blist - Issue tracker: http://github.com/DanielStutzbach/blist/issues -- Daniel Stutzbach, Ph.D. President, Stutzbach Enterprises, LLC <http://stutzb

ANN: winreg_unicode 0.5.0

2010-07-08 Thread Daniel Stutzbach
zbach/winreg_unicode/issues Source code: http://github.com/DanielStutzbach/winreg_unicode -- Daniel Stutzbach, Ph.D. President, Stutzbach Enterprises, LLC <http://stutzbachenterprises.com> -- http://mail.python.org/mailman/listinfo/python-list

Re: Fast Efficient way to transfer an object to another list

2010-05-01 Thread Daniel Stutzbach
t is ordered, we may be able to help you come up with a clever way to remove an item cheaply. -- Daniel Stutzbach, Ph.D. President, Stutzbach Enterprises, LLC <http://stutzbachenterprises.com> -- http://mail.python.org/mailman/listinfo/python-list

Re: negative "counts" in collections.Counter?

2010-03-08 Thread Daniel Stutzbach
;: -1}) >>> c = Counter({'red': 1}) >>> c2 = Counter({'red': 2}) >>> c - c2 Counter() -- Daniel Stutzbach, Ph.D. President, Stutzbach Enterprises, LLC <http://stutzbachenterprises.com> -- http://mail.python.org/mailman/listinfo/python-list

Re: Queue peek?

2010-03-02 Thread Daniel Stutzbach
On Tue, Mar 2, 2010 at 1:58 PM, Martin P. Hellwig < martin.hell...@dcuktec.org> wrote: > What actually happens if multiple threads at the same time, write to a > shared dictionary (Not using the same key)? > All of Python's built-in types are thread safe. Both updates wi

Re: The best way to check if two lists have identical values

2010-02-25 Thread Daniel Stutzbach
> matters. > Order and repetitions matter: list1 == list2 Repetition matters, order does not: sorted(list1) == sorted(list2) # items must be comparable Neither matters: set(list1) == set(list2) # items must be hashable -- Daniel Stutzbach, Ph.D. President, Stutzbach Enterprises, LLC <http://s

Re: Efficiently building ordered dict

2010-02-22 Thread Daniel Stutzbach
27;, 6: 'b', -5: 'c'}) >>> my_dict.keys() [-5, 1, 6] >>> my_dict[2] = 'd' >>> my_dict.keys() [-5, 1, 2, 6] It's available here: http://pypi.python.org/pypi/blist/ -- Daniel Stutzbach, Ph.D. President, Stutzbach Enterprises, LLC <http://stutzbachenterprises.com> -- http://mail.python.org/mailman/listinfo/python-list

Re: Efficient way to break up a list into two pieces

2010-02-20 Thread Daniel Stutzbach
d only O(log n) time to trim l1. You'd use it something like this: >>> from blist import blist >>> l1 = blist() >>> # Here, populate l1 as you normally would >>> l2 = l1[10:] >>> del l1[10:] It's available at: http://pypi.python.org/pypi/bli

Re: The future of "frozen" types as the number of CPU cores increases

2010-02-17 Thread Daniel Stutzbach
ge collector. > A concurrent garbage collector for frozen object would still need to walk unfrozen objects, to find references to frozen objects. -- Daniel Stutzbach, Ph.D. President, Stutzbach Enterprises, LLC <http://stutzbachenterprises.com> -- http://mail.python.org/mailman/listinfo/python-list

Re: Is a merge interval function available?

2010-02-10 Thread Daniel Stutzbach
On Wed, Feb 10, 2010 at 5:23 PM, Peng Yu wrote: > I'm wondering there is already a function in python library that can > merge intervals. > Not in the standard library, but this package may help: http://pypi.python.org/pypi/interval -- Daniel Stutzbach, Ph.D. President, Stutzba

Re: "if {negative}" vs. "if {positive}" style (was: New to Python)

2010-02-09 Thread Daniel Stutzbach
If they're both long, I factor out one or both of the blocks into functions. -- Daniel Stutzbach, Ph.D. President, Stutzbach Enterprises, LLC <http://stutzbachenterprises.com/> -- http://mail.python.org/mailman/listinfo/python-list

ANN: blist 1.1.1 - now with sortedlist, sortedset, and sorteddict

2010-01-31 Thread Daniel Stutzbach
le(x) # y is a btuple with > 500 million elements Feedback We're eager to hear about your experiences with the blist. You can email me at dan...@stutzbachenterprises.com. Alternately, bug reports and feature requests may be reported on our bug tracker at: http://github.com/DanielStutzbach/blist/issues -- Daniel Stutzbach, Ph.D. President, Stutzbach Enterprises, LLC <http://stutzbachenterprises.com/> -- http://mail.python.org/mailman/listinfo/python-list

Re: For loop searching takes too long!

2010-01-28 Thread Daniel Stutzbach
a number between 1 and your sum without generating each and every one. choice = random.randrange(1, sum(i[0] for i in myList)+1) -- Daniel Stutzbach, Ph.D. President, Stutzbach Enterprises, LLC <http://stutzbachenterprises.com> -- http://mail.python.org/mailman/listinfo/python-list

Re: ISO module for binomial coefficients, etc.

2010-01-27 Thread Daniel Stutzbach
1 return part_product(n, k) * part_product(k+2, m) def n_minus_num_of_bits(v): w = v if w >= 2**32-1: raise OverflowError w -= (0x & w) >> 1 w = (w & 0x3333) + ((w >> 2) & 0x) w = w + (w >> 4) & 0x0f0f0f0f w += w >&g

Re: list.pop(0) vs. collections.dequeue

2010-01-25 Thread Daniel Stutzbach
bound to have different opinions about which operations are most important and where lies the best tradeoff between different operations (as well as code complexity). I am not sure why you feel so strongly that particular spot is best. Obviously, I prefer a slightly different spot, but I also respect t

Re: list.pop(0) vs. collections.dequeue

2010-01-24 Thread Daniel Stutzbach
exist as a third-party module. -- Daniel Stutzbach, Ph.D. President, Stutzbach Enterprises, LLC -- http://mail.python.org/mailman/listinfo/python-list

Re: list.pop(0) vs. collections.dequeue

2010-01-22 Thread Daniel Stutzbach
on with the built-in list here: http://stutzbachenterprises.com/performance-blist -- Daniel Stutzbach, Ph.D. President, Stutzbach Enterprises, LLC <http://stutzbachenterprises.com> -- http://mail.python.org/mailman/listinfo/python-list

Re: Sorted dictionary

2010-01-21 Thread Daniel Stutzbach
On Thu, Jan 21, 2010 at 12:45 PM, Jan Kaliszewski wrote: > Please note that I used funcions from bisect, that use binary search. > > Doesn't it take O(log n) time? > It takes O(log n) time to find the point to insert, but O(n) time to perform the actual insertion. -- Danie

Re: Sorted dictionary

2010-01-21 Thread Daniel Stutzbach
sort. > Indeed. In fact, blist 1.1 (to be released within a month or so) will include sorteddict, sortedset, sortedlist, weaksortedset, and weaksortedlist types. -- Daniel Stutzbach, Ph.D. President, Stutzbach Enterprises, LLC <http://stutzbachenterprises.com> -- http://mail.python.org

Re: iterators and views of lists

2009-12-16 Thread Daniel Stutzbach
s(seq[i]) Alternately, if I'm using the blist extension type that I wrote, then seq[1:] is O(log n). http://pypi.python.org/pypi/blist/ -- Daniel Stutzbach, Ph.D. President, Stutzbach Enterprises, LLC <http://stutzbachenterprises.com> -- http://mail.python.org/mailman/listinfo/python-list

Re: iterators and views of lists

2009-12-16 Thread Daniel Stutzbach
On Wed, Dec 16, 2009 at 7:33 AM, Peter Otten <__pete...@web.de> wrote: > islice() could be changed to special-case lists and tuples, but that feels > a > bit unclean. > How about special-casing objects that implement collections.Sequence? -- Daniel Stutzbach, Ph.D. Pr

Re: treaps in python

2009-12-14 Thread Daniel Stutzbach
ibute#distribute-setup-py -- Daniel Stutzbach, Ph.D. President, Stutzbach Enterprises, LLC <http://stutzbachenterprises.com> -- http://mail.python.org/mailman/listinfo/python-list

Re: KeyboardInterrupt

2009-12-10 Thread Daniel Stutzbach
tting there in t.join() with no exception handler around it. -- Daniel Stutzbach, Ph.D. President, Stutzbach Enterprises, LLC <http://stutzbachenterprises.com> -- http://mail.python.org/mailman/listinfo/python-list

Re: non-copy slices

2009-11-19 Thread Daniel Stutzbach
ce, though. That takes O(n) time if you're taking a big slice. -- Daniel Stutzbach, Ph.D. President, Stutzbach Enterprises, LLC <http://stutzbachenterprises.com> -- http://mail.python.org/mailman/listinfo/python-list

Re: non-copy slices

2009-11-18 Thread Daniel Stutzbach
it -s 'from blist import blist' 'small_list=blist([0])' ''BIG_list=small_list*2**29' 'BIG_slice=BIG_list[4:-5]' 1 loops, best of 3: 21.5 usec per loop -- Daniel Stutzbach, Ph.D. President, Stutzbach Enterprises, LLC <http://stutzbachenterprises.com> -- http://mail.python.org/mailman/listinfo/python-list

ANN: blist 1.0.2

2009-11-01 Thread Daniel Stutzbach
es in debug builds - Ported tests to run under Python 2.6 and Python 3.1 (but no longer Python 2.5) - Got rid of warnings on non-ix86 platforms -- Daniel Stutzbach, Ph.D. President, Stutzbach Enterprises, LLC <http://stutzbachenterprises.com> -- http://mail.python.org/mailman/listinfo/python-list

Re: efficient running median

2009-10-13 Thread Daniel Stutzbach
_median if my_median < value: my_median += step_size else: my_median -= step_size Let me know if you have any questions about it. -- Daniel Stutzbach, Ph.D. President, Stutzbach Enterprises, LLC <http://stutzbachenterprises.com> -- http://mail.python.org/mailman/listinfo/python-list

Re: iterate over list while changing it

2009-09-30 Thread Daniel Stutzbach
[1, 2, 3, 4, 5, 6] i = 0 while i < len(a): x = a[i] if x == 3: a.pop(i) i += 1 continue if x == 4: a.append(88) print "i", i, "x", x i += 1 -- Daniel Stutzbach, Ph.D. President, Stutzbach Enterprises, LLC <http://stutzbachenterprises.com> -- http://mail.python.org/mailman/listinfo/python-list

Re: super() and multiple inheritance failure

2009-09-25 Thread Daniel Stutzbach
iour. > super() does not have the behavior that I would have expected, either, and IMO the documentation is unenlightening. I found the following website helpful in understanding what super() *actually* does (though I do not support the author's hyperbolic criticisms): http://fuhm.net/sup

Re: Doubley imported module caused devastating bug

2009-09-24 Thread Daniel Stutzbach
On Thu, Sep 24, 2009 at 2:51 PM, Ethan Furman wrote: > I believe that modules are imported only once > That's *mostly* true, but try this one: A.py: print 'Importing A' import B B.py: print 'Importing B' import A Cashew:/tmp$ python2.5 B.py Importing B Imp

Re: delete items from list by indices

2009-09-23 Thread Daniel Stutzbach
n to that problem. >>> items = ["a", "b", "c", "d"] > >>> delenda = set([0, 3]) > >>> items = [item for index, item in enumerate(items) if index not in > delenda] > >>> items > ['b', 'c']

Re: Creating a local variable scope.

2009-09-12 Thread Daniel Stutzbach
wanted to keep. > You're absolutely right. My apologies. I need to learn not to post to mailing lists first thing in the morning! ;-) -- Daniel Stutzbach, Ph.D. President, Stutzbach Enterprises, LLC <http://stutzbachenterprises.com> -- http://mail.python.org/mailman/listinfo/python-list

Re: Creating a local variable scope.

2009-09-12 Thread Daniel Stutzbach
. Observe: Python 2.6.2 (r262:71600, Apr 15 2009, 07:20:39) [GCC 3.4.4 (cygming special, gdc 0.12, using dmd 0.125)] on cygwin Type "help", "copyright", "credits" or "license" for more information. >>> with open('/dev/null'

Re: Creating a local variable scope.

2009-09-11 Thread Daniel Stutzbach
hs back: http://mail.python.org/pipermail/python-ideas/2009-July/005114.html <http://mail.python.org/pipermail/python-ideas/2009-July/005114.html%20> -- Daniel Stutzbach, Ph.D. President, Stutzbach Enterprises, LLC <http://stutzbachenterprises.com> -- http://mail.python.org/mailman/listinfo/python-list

Re: Simple addition to random module - Student's t

2009-09-03 Thread Daniel Stutzbach
r cumulative distribution functions require math functions not currently provided by Python (erf, gamma, etc.). (http://bugs.python.org/issue3366 includes a patch to provide them) -- Daniel Stutzbach, Ph.D. President, Stutzbach Enterprises, LLC <http://stutzbachenterprises.com> -- http://mail.

Re: List insertion cost

2009-07-21 Thread Daniel Stutzbach
), you can use the blist extension type from http://pypi.python.org/pypi/blist/ -- Daniel Stutzbach, Ph.D. President, Stutzbach Enterprises, LLC <http://stutzbachenterprises.com> -- http://mail.python.org/mailman/listinfo/python-list

Re: No trees in the stdlib?

2009-06-26 Thread Daniel Stutzbach
tic performance characteristics. Copying a blist is O(1), so the functional-programming types can wrap it in non-mutating semantics if they so choose. ;) -- Daniel Stutzbach, Ph.D. President, Stutzbach Enterprises, LLC <http://stutzbachenterprises.com> -- http://mail.python.org/mailman/listinfo/python-list

Re: python list handling and Lisp list handling

2009-04-27 Thread Daniel Stutzbach
e called the "blist" that has the same methods as a Python list, but has better asymptotic performance for many operations. That way I can write use the list in the most natural way without having to worry about accidentally hitting a O(n) method. http://pypi.python.org/pypi/blist/ --

Re: Programming in Python with a view to extending in C at a later date.

2009-04-20 Thread Daniel Stutzbach
lways outweighed the cost of later translating some of the code. Hope that helps, -- Daniel Stutzbach, Ph.D. President, Stutzbach Enterprises, LLC <http://stutzbachenterprises.com> -- http://mail.python.org/mailman/listinfo/python-list