Re: Few things

2004-11-30 Thread bearophile
to the second parameter of "int", this also allows to specify any base). 2) a symbol to represent a smaller class of possibilities, like 0=2, 1=8, 2=10, 3=16, 4=64. Instead of such digits a letter can be used: a=2, b=8, c=10, etc. I think the first option is better. So integer numbe

Re: Few things

2004-11-30 Thread bearophile
umber, as a small subscripted number (but I understand your following explanations). >I'll also mention that two of your 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 us

Re: [Python-Dev] PEP: __source__ proposal

2004-12-05 Thread bearophile
cell that follows the output one). Some similar "improvements" of the CPython shell can be useful... but I think you first need to look in many places (Smalltalk, LOGO, Mathematica, Mathcad, etc.) to find the best ideas to copy from. Bear hugs, Bearophile -- http://mail.python.org/mailman/listinfo/python-list

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

2009-11-29 Thread Bearophile
r.add(s[i : j]) print >> fout, len(r) - 1 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
is is worth doing especially 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
ide all loops), the performance difference 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
to improve 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: Graph library for Python

2009-12-09 Thread Bearophile
/py_graph... > > 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: 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

Re: Graph library for Python

2009-12-10 Thread Bearophile
esigned 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" gra

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
ctory that will instanciate appropriate 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: 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: iterators and views of lists

2009-12-16 Thread Bearophile
want to use all the time learning how to use the language 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

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 > por

Vectorized laziness 2

2009-12-21 Thread Bearophile
q.com/news/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: syntax error : first python program

2009-12-23 Thread Bearophile
re, something that contains "indentation" in it :-) Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list

Missing collections

2009-12-26 Thread Bearophile
ot; or something like that. So you write: import 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: Symbols as parameters?

2010-01-21 Thread Bearophile
(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
useful to have 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

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: flow control and nested loops

2009-09-26 Thread Bearophile
continue OUTER if test2(x, y, z): continue INNER frobnicate(x, y, z) glortz(x, y) splat(x) Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list

Re: python memory use

2009-09-30 Thread Bearophile
ava. I don't know). Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list

Re: Quick compare string to list

2009-09-30 Thread Bearophile
ce :-) http://en.wikipedia.org/wiki/Aho-Corasick_algorithm 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: 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: Enormous Input and Output Test

2009-10-04 Thread Bearophile
there are ways to write a Python program to solve this problem). People at Google 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 fas

Re: Q: sort's key and cmp parameters

2009-10-06 Thread Bearophile
end have added something like that in the std lib, but with a weird name like SchwartzSort that's surely not the first standard sort 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

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 li

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 seem

Re: Q: sort's key and cmp parameters

2009-10-07 Thread Bearophile
a program have to be optimized for different things, computer performance, or programmer performance. Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list

Re: The rap against "while True:" loops

2009-10-12 Thread Bearophile
epeat-until, but this is less nice, because the condition is reversed compared to the one you use in a while-do loop) construct. Give me a do-while and a good amount of breaks&while True in my Python code will be removed. Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list

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

2009-10-16 Thread Bearophile
ailable for lists, 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
still among the faster ways to implement that algorithm. Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list

Re: Reverse Iteration Through Integers

2009-10-19 Thread Bearophile
092816286 ** 123))[:35] '65852401624276201339740994895755844' """ # code removed ... if __name__ == "__main__": import doctest doctest.testmod() print "Doctests done" Using tests (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
ence abhors 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/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: #define (from C) in Python

2009-11-13 Thread Bearophile
be impossible to add them to this language, because of how it uses references. In Python you 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: Common area of circles

2010-02-04 Thread Bearophile
probably higher. If you implement this second solution you can 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: 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, &#

Re: Voronoi diagram algorithm (Fortune’s sweepline )

2009-06-11 Thread Bearophile
using hash maps (named dicts 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
(and slower). 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: TypeError: int argument required

2009-06-15 Thread Bearophile
itive to split such string in two or more parts, for example (untested): style = ("fill:blue; stroke:pink; stroke-width:5; " "fill-opacity:0.1; stroke-opacity:0.9") print >> fo, ' ' % (abs_x, abs_y, w, h, style) Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list

Re: Input problem

2009-06-16 Thread Bearophile
sions (like 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,

Re: Good books in computer science?

2009-06-19 Thread Bearophile
ery often you learn in the wrong way, 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: 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-27 Thread Bearophile
n ShedSkin), so they are somewhat useful again :-) 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: 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: Is code duplication allowed in this instance?

2009-07-03 Thread Bearophile
or tools) that allow 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
solving skills, and much less important than learning why solving problems has to became their purpose and pleasure :-) Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list

Re: tough-to-explain Python

2009-07-07 Thread Bearophile
he problem is that teaching is a niche activity (even if a very important one). PLT Scheme is one of the few 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: count

2009-07-08 Thread Bearophile
# 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/listinfo/python-list

Re: count

2009-07-09 Thread Bearophile
000) >     test_func(summer, 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
ternal code in C/C++/D/Fortran and interfacing 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
Python applications, or export 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: 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: list of all possible values

2009-07-13 Thread Bearophile
'a'), ('a', 'b'), ('a', 'c'), ('b', 'a'), ('b', 'b'), ('b', 'c'), ('c', 'a'), ('c', 'b'), ('c', 'c')] 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

Re: turtle dump

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

Re: ANN: psyco V2

2009-07-17 Thread Bearophile
o1.6 has 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: ANN: Shed Skin 0.2, an experimental (restricted) Python-to-C++ compiler

2009-07-20 Thread Bearophile
ce timings, can you please show me the Python, 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
hon list from Cython and using a C "array" allocated with a malloc from Cython. 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
inite loop (there's a compilation flag 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
the Psyco program #2 is faster 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-21 Thread Bearophile
/cheval/file/46797c3a5136/chevalx.pyx#l1 Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list

Re: How to comment constant values?

2009-07-26 Thread Bearophile
iables? 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-26 Thread Bearophile
r DMD compiler): http://pyd.dsource.org/ Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list

Re: The longest word

2009-07-28 Thread Bearophile
So you just have to give it a function (reference) that given the word spits its 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: set variable to looping index?

2009-07-30 Thread Bearophile
ample of the contents of var1_fn, var2_fn, etc. 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: Overlap in python

2009-08-04 Thread Bearophile
x27;, 'b', 'c'], [15, 23, 'd', 'e']] If you have have a lot of data then it will be too much slow, and you have to use a more complex algorithm. 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
mulating blocks along the way. Oh, right, that's 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: 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/mailm

Re: intricated functions: how to share a variable

2009-08-05 Thread Bearophile
s them an argument and you take an argument as return value. Such return value will be the new version of the value you talk about. 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
ink its name may be changed to Fusil, I don't know). 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. B

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: 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

Re: Plotting Quadratic Functions, pygame

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

Re: flatten a list of list

2009-08-16 Thread Bearophile
o solve this situation. A better way is to create (or copy) a flatten that's efficient and well tested & debugged, put it into some library of utilities, and then use import&use it when it's needed. Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list

Re: Annoying octal notation

2009-08-23 Thread Bearophile
ant to follow Python's lead and either 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. The

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,

Re: Algorithms as objects?

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

Re: Can't set attribute?!

2009-09-02 Thread Bearophile
for. It's mostly useful for small classes that don't need subclassing that have to be instantiated a large number of times. As far as I know, it's meant as a memory optimization, not a way to define things in a more explicit way. Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list

Re: The future of Python immutability

2009-09-06 Thread Bearophile
ven if it avoids bugs in user code. Implementing it in Python in a simple enough way looks like a good topic for advanced research :-) Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list

Vectorized laziness inside

2009-09-10 Thread Bearophile
the itertools module. I'll do some experiments to see if the ideas of such vectorized 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: Creating a local variable scope.

2009-09-11 Thread Bearophile
split a function 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

Re: Google Code Jam language usage

2009-09-15 Thread Bearophile
has better templates and CTFE http://en.wikipedia.org/wiki/Compile_time_function_execution ) such times can become important, because some precomputations can be moved to compile time. If compilation time counts too, 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
im1, di print "Case #%d: %04d" % (t+1, dim1[len_b - 1]) import psyco; psyco.full() main() Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list

Static typing, Python, D, DbC

2010-09-11 Thread Bearophile
problems, the 'random' module was empty, 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: Static typing, Python, D, DbC

2010-09-12 Thread Bearophile
;t be certain, you are able reduce 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
ww.python.org/dev/peps/pep-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.

Re: Static typing, Python, D, DbC

2010-09-13 Thread Bearophile
D you may also use enforce(), that's essentially a camouflaged throw/raise statement, if you use it outside DbC 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: palindrome iteration

2010-09-14 Thread Bearophile
L10 Those two calls to _tolower inside the loop don't help performance, but if you know your strings contain only upper case and lower case chars, and you are able to assume few other things on your machine, it's easy to replace them with non-portable inlined code. The addl and subl are the i++ and j--, GCC has moved them at top as commonly done optimization. The first cmpl is the (i < j) test, and the jge is a jump that ends the loop when it's the right time to do so. The movsbl go read one char, and put them in eax. The movl are necessary to set arguments for the call 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