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
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
the probabilities of some
bugs to happen.
Bye,
bearophile
--
http://mail.python.org/mailman/listinfo/python-list
-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
, 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
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
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
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
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
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
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
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
/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
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
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
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
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
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
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
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
...
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
fout.close()
print time() - t
main()
Bye,
bearophile
--
http://mail.python.org/mailman/listinfo/python-list
when you use
Psyco).
Bye,
bearophile
--
http://mail.python.org/mailman/listinfo/python-list
will surely
grow.
Bye,
bearophile
--
http://mail.python.org/mailman/listinfo/python-list
your Python solution to the problem 99, you can show us the
code here...
Bye,
bearophile
--
http://mail.python.org/mailman/listinfo/python-list
rely on convention, writing their names ALL_UPPERCASE.
Bye,
bearophile
--
http://mail.python.org/mailman/listinfo/python-list
Try creation an extension module with ShedSkin.
Bye,
bearophile
--
http://mail.python.org/mailman/listinfo/python-list
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
(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
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
, 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
to implement that algorithm.
Bye,
bearophile
--
http://mail.python.org/mailman/listinfo/python-list
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
performance, or programmer
performance.
Bye,
bearophile
--
http://mail.python.org/mailman/listinfo/python-list
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
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
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
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
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
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
)
glortz(x, y)
splat(x)
Bye,
bearophile
--
http://mail.python.org/mailman/listinfo/python-list
, 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
- 1])
import psyco; psyco.full()
main()
Bye,
bearophile
--
http://mail.python.org/mailman/listinfo/python-list
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
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
for advanced research :-)
Bye,
bearophile
--
http://mail.python.org/mailman/listinfo/python-list
creating nested functions on the fly, etc.
Bye,
bearophile
--
http://mail.python.org/mailman/listinfo/python-list
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
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
) 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
be better.
Bye,
bearophile
--
http://mail.python.org/mailman/listinfo/python-list
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
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
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
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
.
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
).
Bye,
bearophile
--
http://mail.python.org/mailman/listinfo/python-list
.
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
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
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
.
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
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
,
bearophile
--
http://mail.python.org/mailman/listinfo/python-list
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
/46797c3a5136/chevalx.pyx#l1
Bye,
bearophile
--
http://mail.python.org/mailman/listinfo/python-list
that avoids some infinite loops, try it).
Bye,
bearophile
--
http://mail.python.org/mailman/listinfo/python-list
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
, 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
Cython.
Bye,
bearophile
--
http://mail.python.org/mailman/listinfo/python-list
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
into a
text file :-)
Bye,
bearophile
--
http://mail.python.org/mailman/listinfo/python-list
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
'), ('c', 'c')]
Bye,
bearophile
--
http://mail.python.org/mailman/listinfo/python-list
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
, 1)
test_func(tupler, 1)
Have you forgotten my function?
Bye,
bearophile
--
http://mail.python.org/mailman/listinfo/python-list
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
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
(): 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
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
to add pre- and post-conditions, class invariants, etc.
Bye,
bearophile
--
http://mail.python.org/mailman/listinfo/python-list
learning why solving problems has to became
their purpose and pleasure :-)
Bye,
bearophile
--
http://mail.python.org/mailman/listinfo/python-list
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
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
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
,
bearophile
--
http://mail.python.org/mailman/listinfo/python-list
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
, 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
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
; 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
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
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
,
bearophile
--
http://mail.python.org/mailman/listinfo/python-list
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
93 matches
Mail list logo