Re: palindrome iteration

2010-09-14 Thread Bearophile
to the tolower function. The last cmpl compares the results of the tolower, and je (jump equal) jumps to the start of the loop if they are equal. Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list

Re: Static typing, Python, D, DbC

2010-09-13 Thread Bearophile
contracts, they are tests that run even in release builds when your contracts are disabled. Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list

Re: Static typing, Python, D, DbC

2010-09-12 Thread Bearophile
the probabilities of some bugs to happen. Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list

Re: Static typing, Python, D, DbC

2010-09-12 Thread Bearophile
-0316/ (it misses few things like loop invariants and loop variants). For me DbC is useful almost as unit-testing (I use them at the same time), this is why in the original post I have said it's one of the things I miss most in Python. Bye, bearophile -- http://mail.python.org/mailman/listinfo

Static typing, Python, D, DbC

2010-09-11 Thread Bearophile
, and it didn't import the new division from the future, so I've had to remove it and reinstall 2.6.6. Is this just a problem of mine? Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list

Re: Splitting a string

2010-04-02 Thread Bearophile
I don't know how fast this is (Python 2.x): from itertools import groupby t = 'si_pos_99_rep_1_0.ita' tuple(int(.join(g)) if h else .join(g) for h,g in groupby(t, str.isdigit)) ('si_pos_', 99, '_rep_', 1, '_', 0, '.ita') It doesn't work with unicode strings. Bye, bearophile -- http

Re: Common area of circles

2010-02-04 Thread Bearophile
implement the first one too, and use it as a test to avoid bugs. Visualizing the triangles with Pygame or MatPlotLib can be useful to look for bugs. Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list

Re: Efficient Running Median

2010-01-23 Thread Bearophile
Very nice. I have added a comment at the bottom, using a circular queue instead of a deque may be faster. Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list

Re: Symbols as parameters?

2010-01-21 Thread Bearophile
this (that warns if you give it a string that contains a keyword) looks not too much hard: direction = Enum(up, down, left, right) Or: direction = Enum(up, down, left, right) Or: direction = Enum(up down left right) Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list

Re: Sorted dictionary

2010-01-21 Thread Bearophile
ordered dicts and sets based on search trees. I'm thinking about B+ trees to use CPU cache locality better. It can be fun :-) Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list

Missing collections

2009-12-26 Thread Bearophile
py.math from py.math import sin x = py.math.cos(1.2) y = sin(1.2) Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list

Re: syntax error : first python program

2009-12-23 Thread Bearophile
Ben Finney: bash# /usr/bin/python sample.py   File sample.py, line 2     name = blah     ^ SyntaxError: invalid syntax Indentation is syntax in Python. But I agree, a little better error message may help there, something that contains indentation in it :-) Bye, bearophile -- http

Vectorized laziness 2

2009-12-21 Thread Bearophile
/2009/12/clojure-11-rc1-transients See: http://clojure.googlegroups.com/web/chunks.pdf (I know they can have some problematic corner cases.) Bye and be well, bearophile -- http://mail.python.org/mailman/listinfo/python-list

Re: iterators and views of lists

2009-12-18 Thread Bearophile
Brendan Miller: I agree though, it doesn't matter to everyone and anyone. The reason I was interested was because i was trying to solve some specific problems in an elegant way. I was thinking it would be cool to make python more usable in programming competitions by giving it its own port of

Re: iterators and views of lists

2009-12-16 Thread Bearophile
itself (think about C++ again). So Python programmers live with a less performing language. When performance of the code is not enough (even with the future Unladen Swallow), they use another language (often to write extensions used from Python code). Bye, bearophile -- http://mail.python.org

Re: Seek support for new slice syntax PEP.

2009-12-15 Thread Bearophile
Steven D'Aprano: I've lost all enthusiasm for discussing language enhancements That's probably the main downside of the moratorium. Humans need to play some to keep their will to work and improve things. Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list

Re: Which graph library is best suited for large graphs?

2009-12-11 Thread Bearophile
Wolodja Wentland: Which library would you choose? This one probably uses low memory, but I don't know if it works still: http://osl.iu.edu/~dgregor/bgl-python/ Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list

Re: switch

2009-12-11 Thread Bearophile
IScore implementation objects that knows what to do. [snip] Thank you very much for bringing back some sanity in this newsgroup, sometimes a good antiexample like yours is better than many explanations. Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list

Re: Graph library for Python

2009-12-10 Thread Bearophile
geremy condra: Since that's released under the python license, I'm going to go ahead and commit the version that includes the topo traversal, but if you have any objections you only need to say the word and I'll take it down. No objections :-) Bye, bearophile -- http://mail.python.org

Re: Graph library for Python

2009-12-10 Thread Bearophile
for different purposes. Bearophile, Tiago- any interest in trying to combine the best parts of our libraries, with an eye towards eventual integration into the standard library? The first thing to do is to ask Guido and Hettinger if they are willing to put a good graph module into the std lib

Re: Graph library for Python

2009-12-09 Thread Bearophile
... and many others..some of the above already seem to be very useful. There's mine too: http://sourceforge.net/projects/pynetwork/ API: http://code.activestate.com/recipes/466329/ Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list

Re: Number of distinct substrings of a string [continuation]

2009-11-29 Thread Bearophile
fout.close() print time() - t main() Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list

Re: Number of distinct substrings of a string [continuation]

2009-11-29 Thread Bearophile
when you use Psyco). Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list

Re: Number of distinct substrings of a string [continuation]

2009-11-29 Thread Bearophile
will surely grow. Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list

Re: Number of distinct substrings of a string [continuation]

2009-11-29 Thread Bearophile
your Python solution to the problem 99, you can show us the code here... Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list

Re: #define (from C) in Python

2009-11-13 Thread Bearophile
rely on convention, writing their names ALL_UPPERCASE. Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list

Re: Writing an emulator in python - implementation questions (for performance)

2009-11-13 Thread Bearophile
Try creation an extension module with ShedSkin. Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list

Re: New syntax for blocks

2009-11-10 Thread Bearophile
r: i think the following syntax would be quite beneficial to replace some redundant if's in python code. http://python.org/dev/peps/pep-3003/ bearophile -- http://mail.python.org/mailman/listinfo/python-list

Re: Reverse Iteration Through Integers

2009-10-19 Thread Bearophile
(and a bit later to use a versioning system) is among the things that have to be taught as soon as possible :-) Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list

Re: Python for Bioinformatics available and in stock

2009-10-19 Thread Bearophile
black boxes, a scientist must have an idea of how all subsystems she/he/hir is using are working inside (that's why using Mathematica can be bad for a scientist, because such person has to write and here magic happens in the produced paper). Bye, bearophile -- http://mail.python.org/mailman

Re: How about adding slice notation to iterators/generators?

2009-10-16 Thread Bearophile
, tuples, strings, arrays, numpy, etc, so adding it to iterators too doesn't look like adding that large amount of information to the mind of the programmer. Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list

Re: The rap against while True: loops

2009-10-16 Thread Bearophile
to implement that algorithm. Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list

Re: Q: sort's key and cmp parameters

2009-10-07 Thread Bearophile
Paul Rubin: Bearophile: sorting, and something that's surely not bug-prone. In such situation having a 'key' argument is *better*. Such sort can be stable. Nothing stops comparison sorting from being stable.  Since the rest of your post seems premised on the opposite, I hope that clears

Re: Q: sort's key and cmp parameters

2009-10-07 Thread Bearophile
performance, or programmer performance. Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list

Re: Q: sort's key and cmp parameters

2009-10-06 Thread Bearophile
they look for... this is bad. So a funny solution to this situation may be the following: to keep only 'key' in the sort/sorted for few years, so the community of Python programmers gets used to 'key' only, and then put 'cmp' back in, for the special cases ;-) Bye, bearophile -- http

Re: Q: sort's key and cmp parameters

2009-10-06 Thread Bearophile
Paul Rubin: bearophile: I am having a very hard type (despite my implementation, explanations, etc) explaining to D programmers why for a flexible general-purpose function a key function argument is often better. They in the end have added something like that in the std lib, but with a weird

Re: Enormous Input and Output Test

2009-10-04 Thread Bearophile
are trying to create a 5 times faster Python (Unladen Swallow project) because they use lot of real-world Python code and they think Python is slow. I've found plenty of situations where CPython code is not fast enough for my purposes. Bye, bearophile -- http://mail.python.org/mailman/listinfo

Re: Q: sort's key and cmp parameters

2009-10-01 Thread Bearophile
Paul Rubin: Yes, think of sorting tree structures where you have to recursively compare them til you find an unequal pair of nodes. That's cute. In what situations do you have to perform such kind of sort? Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list

Re: python memory use

2009-09-30 Thread Bearophile
memory usage. Similar things may be done by the LLVM too in future: http://llvm.org/pubs/2005-06-12-MSP-PointerCompSlides.pdf Maybe someday 64-bit CPython will do the same, or maybe UnlandenSwallow or PyPy (Jthon in a sense may do it already if you use it on a 64 bit Java. I don't know). Bye, bearophile

Re: Quick compare string to list

2009-09-30 Thread Bearophile
There are probably C implementations that can be used from Python, like: http://hkn.eecs.berkeley.edu/~dyoo/python/ahocorasick/ Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list

Re: flow control and nested loops

2009-09-26 Thread Bearophile
) glortz(x, y) splat(x) Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list

Re: Google Code Jam language usage

2009-09-15 Thread Bearophile
, then in such contests Python will improve its stats (a slow compilation time can be bad for the testing of the code, so it's a disadvantage for the programmer too). Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list

Re: Google Code Jam language usage

2009-09-15 Thread Bearophile
- 1]) import psyco; psyco.full() main() Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list

Re: Creating a local variable scope.

2009-09-11 Thread Bearophile
is to define an inner function, that's one of their main purposes. No need to add other things to the language as the OP suggests. Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list

Vectorized laziness inside

2009-09-10 Thread Bearophile
laziness can improve lazy generators in D. I may even test the idea of keeping arrays with holes. Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list

Re: The future of Python immutability

2009-09-06 Thread Bearophile
for advanced research :-) Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list

Re: Algorithms as objects?

2009-08-27 Thread Bearophile
creating nested functions on the fly, etc. Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list

Re: Graph library recommendations for large graphs

2009-08-24 Thread Bearophile
You may try the Python bindings for the Boost Graph Library, the graph you talk about may fit in 2GB of a 32 bit OS too (this is the first link I have found, it's a lot of time I don't use those graph bindings): http://banyan.usc.edu/log/c_cpp/boost-graph-library-python-bindings Bye, bearophile

Re: Annoying octal notation

2009-08-23 Thread Bearophile
drop support for oct literals completely, or require a 0o prefix:http://d.puremagic.com/issues/show_bug.cgi?id=2656 Yes, people in the D community are trying to improve things, but it's a slow and painful process, and often it goes nowhere. There's lot of politics. Bye, bearophile -- http

Re: flatten a list of list

2009-08-16 Thread Bearophile
) a flatten that's efficient and well tested debugged, put it into some library of utilities, and then use importuse it when it's needed. Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list

Re: Plotting Quadratic Functions, pygame

2009-08-14 Thread Bearophile
be better. Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list

Re: Need cleanup advice for multiline string

2009-08-11 Thread Bearophile
Robert Dailey: This breaks the flow of scope. Would you guys solve this problem by moving failMsg into global scope? Perhaps through some other type of syntax? There are gals too here. This may help: http://docs.python.org/library/textwrap.html#textwrap.dedent Bye, bearophile -- http

Re: Bug or feature: double strings as one

2009-08-07 Thread Bearophile
durumdara: I wanna ask that is a bug or is it a feature? For me it's a bug-prone antifeature. Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list

Re: ANN: Python for Bioinformatics book

2009-08-06 Thread Bearophile
Sebastian Bassi: All code is also available at thehttp://py3.us/##where ## is the code number, for example:http://py3.us/57 The book looks interesting, but that doesn't look like a good way to show/offer the code. I suggest to also put it into a zip that can be downloaded. Bye, bearophile

Re: Overlap in python

2009-08-05 Thread Bearophile
Albert van der Horst: That is an algorithmic question and has little to do with Python. Yes, but comp.lang.python isn't comp.lang.c, that kind of questions are perfectly fine here. They help keep this place from becoming boring. Bye, bearophile -- http://mail.python.org/mailman/listinfo/python

Re: intricated functions: how to share a variable

2009-08-05 Thread Bearophile
. Python3+ has the nonlocal statement that may do what you ask for. But as many other things in Python it must be used with judgment, to avoid writing intricate code. Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list

Re: Parsing Binary Structures; Is there a better way / What is your way?

2009-08-05 Thread Bearophile
). Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list

Re: Overlap in python

2009-08-04 Thread Bearophile
. If your intervals are many, they are small, and they are spread in a not too much large range of possible values, you can create an integer array of indexes, and you can paint intervals on it. Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list

Re: Overlap in python

2009-08-04 Thread Bearophile
the usual simple solution. Silly me for showing the dumb quadratic solution :-) The pixelmap approach may be faster if you have tons of small intervals in a not too much large range. Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list

Re: Overlap in python

2009-08-04 Thread Bearophile
kj:     # connect the nodes     for i in range(len(parts) - 1):         part_i = parts[i]         for j in range(i + 1, len(parts)): Note that's O(N^2), see the O(sort) standard solution by Mark Dickinson. Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list

Re: set variable to looping index?

2009-07-30 Thread Bearophile
. Generally you can create a dict: results = {} And then fill it with name-result pairs: name = value.split('_')[0] results[name] = some_function(value) Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list

Re: The longest word

2009-07-28 Thread Bearophile
length, such function is len itself. If you instead want to find the position of the longest word the program gets a little longer. Ask if you need something different. Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list

Re: How to comment constant values?

2009-07-26 Thread Bearophile
, bearophile -- http://mail.python.org/mailman/listinfo/python-list

Re: ANN: Shed Skin 0.2, an experimental (restricted) Python-to-C++ compiler

2009-07-26 Thread Bearophile
that I did use an extra trick: unsigned integers, so it needs just two tests to see if a number is in the 0-5, 0-5 square :-) Note that Pyd, the Python-D bridge, may work with the latest DMD version still (and it works if you use a bit older DMD compiler): http://pyd.dsource.org/ Bye, bearophile

Re: ANN: Shed Skin 0.2, an experimental (restricted) Python-to-C++ compiler

2009-07-22 Thread Bearophile
/46797c3a5136/chevalx.pyx#l1 Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list

Re: ANN: Shed Skin 0.2, an experimental (restricted) Python-to-C++ compiler

2009-07-21 Thread Bearophile
that avoids some infinite loops, try it). Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list

Re: ANN: Shed Skin 0.2, an experimental (restricted) Python-to-C++ compiler

2009-07-21 Thread Bearophile
than your C code :-) If you learn how to use it well, Psyco1.6 can often lead to very good performance. But lot of people don't know how to use Psyco well (I too am ignorant: I don't know how to profile Python programs yet). Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list

Re: ANN: Shed Skin 0.2, an experimental (restricted) Python-to-C++ compiler

2009-07-20 Thread Bearophile
, Java and C code versions? I may do more tests. The purpose of all those example programs in ShedSkin is to find bugs and to find details to speedup. Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list

Re: ANN: Shed Skin 0.2, an experimental (restricted) Python-to-C++ compiler

2009-07-20 Thread Bearophile
Cython. Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list

Re: ANN: psyco V2

2009-07-17 Thread Bearophile
a profile() function, but I am not much able to use it yet. Can you tell me how to find a sorted list of the running time of all functions/methods of a Psyco-digested program? Bye and thank you, bearophile -- http://mail.python.org/mailman/listinfo/python-list

Re: turtle dump

2009-07-16 Thread Bearophile
into a text file :-) Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list

Re: A question of style .....

2009-07-15 Thread Bearophile
tuxagb: If I have to write an extension module with many objects, how can I organizing the code? I think: every object in a separate file, and a last file with the PyInit_. function. But is unmenageable . Solutions? What do you think about using Cython? Bye, bearophile -- http

Re: list of all possible values

2009-07-13 Thread Bearophile
'), ('c', 'c')] Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list

Re: psyco V2 beta2 benchmark

2009-07-11 Thread Bearophile
larudwer, is that time_subdist subdist(i) a bad worsening? Something to be fixed in Psyco2? Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list

Re: count

2009-07-09 Thread Bearophile
, 1)     test_func(tupler, 1) Have you forgotten my function? Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list

Re: Psyco 64 bits

2009-07-09 Thread Bearophile
with it with a plethora of means, like ctypes, swig, PIL, Pyd, Boost.Python, Inline, and many other. Running speed is a big problem in many Python programs, so they have invented an army of possible solutions. Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list

Re: can i write a assemly language programs in python

2009-07-09 Thread Bearophile
them to standard assembly languages. I have never used CorePy yet, but it's an awesome project ^_^ With some care and work even Python programs can get fast enough :-) Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list

Re: count

2009-07-08 Thread Bearophile
(): yield 1 leniter(foo1()) 1 # This code is faster than: sum(1 for _ in iterator) if hasattr(iterator, __len__): return len(iterator) nelements = 0 for _ in iterator: nelements += 1 return nelements Bye, bearophile -- http://mail.python.org/mailman

Re: tough-to-explain Python

2009-07-07 Thread Bearophile
environments (beside Squeak, Python itself, and little more) that look refined and implemented well enough for such purpose. See you later, bearophile -- http://mail.python.org/mailman/listinfo/python-list

Re: Is code duplication allowed in this instance?

2009-07-03 Thread Bearophile
to add pre- and post-conditions, class invariants, etc. Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list

Re: Clarity vs. code reuse/generality

2009-07-03 Thread Bearophile
learning why solving problems has to became their purpose and pleasure :-) Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list

Re: Searching equivalent to C++ RAII or deterministic destructors

2009-07-02 Thread Bearophile
Ulrich Eckhardt: a way to automatically release the resource, something which I would do in the destructor in C++. Is this helpful? http://effbot.org/pyref/with.htm Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list

Re: Is Psyco good for Python 2.6.1?

2009-07-02 Thread Bearophile
Russ P.: Python works well to me on Python 2.6+, on Windows. You can find a compiled version too, around. Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list

Re: Specific iterator in one line

2009-06-30 Thread Bearophile
Filip Gruszczyński: [1, 0, 0, 1] - ['b', 'b', 'a', 'a', 'b', 'b'] I like this version (43 golf holes), it's readable enough: [c for d in[1,0,0,1]for c in(a,bb)[d]] Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list

Re: Good books in computer science?

2009-06-27 Thread Bearophile
, bearophile -- http://mail.python.org/mailman/listinfo/python-list

Re: What is the best method to match a pattern in set of lines

2009-06-20 Thread Bearophile
This is a small OT post, sorry. Dennis Lee Bieber, may I ask why most or all your posts are set to No- Archive? HTTP://www.bestiaria.com/ I think there are other furries beside you around here. Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list

Re: Good books in computer science?

2009-06-19 Thread Bearophile
, or in a not much efficient way. Howard Gardner too has written about such topic. Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list

Re: Input problem

2009-06-16 Thread Bearophile
formulas) in your program in a quick, simple and unsafe way... In Python3+ they have removed input() and they have renamed raw_input () as input(). You can have the functionality of 2.x input() with eval (input()). (I think Python3 developers have taken the right choices here). Bye, bearophile

Re: TypeError: int argument required

2009-06-15 Thread Bearophile
; stroke-width:5; fill-opacity:0.1; stroke-opacity:0.9) print fo, 'rect x=%f y=%f width=%d height=%d style=%s/ ' % (abs_x, abs_y, w, h, style) Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list

Re: Voronoi diagram algorithm (Fortune’s sweepline )

2009-06-12 Thread Bearophile
dorzey: Found this python implementation: http://www.oxfish.com/python/voronoi.py Looks very nice, and it may be ShedSkin-compilable too. Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list

Re: Voronoi diagram algorithm (Fortune’s sweepline )

2009-06-11 Thread Bearophile
in Python), because they are both essential in computer science and in Python. Ask if you need some help regarding dicts and sets. Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list

Re: Voronoi diagram algorithm (Fortune’s sweepline )

2009-06-11 Thread Bearophile
, bearophile -- http://mail.python.org/mailman/listinfo/python-list

Re: Few things

2004-11-30 Thread bearophile
examples; afa35a_16 and Fi3pK_64, are valid python variable names Uh, I am sorry... As I feared, I have written a silly thing :-) I much prefer just using decimal and offering the proper base notation afterwards in a comment... I agree. I'll avoid to give hugs, Bearophile -- http