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
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
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
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
is is worth doing especially when you use
Psyco).
Bye,
bearophile
--
http://mail.python.org/mailman/listinfo/python-list
ide all loops), the performance difference will surely
grow.
Bye,
bearophile
--
http://mail.python.org/mailman/listinfo/python-list
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
/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
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
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
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
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
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
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
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
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, something
that contains "indentation" in it :-)
Bye,
bearophile
--
http://mail.python.org/mailman/listinfo/python-list
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
(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
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
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
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
ava. I don't know).
Bye,
bearophile
--
http://mail.python.org/mailman/listinfo/python-list
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
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
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
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
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
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
a program have to be
optimized for different things, computer performance, or programmer
performance.
Bye,
bearophile
--
http://mail.python.org/mailman/listinfo/python-list
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
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
still among the faster ways
to implement that algorithm.
Bye,
bearophile
--
http://mail.python.org/mailman/listinfo/python-list
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
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
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
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
Try creation an extension module with ShedSkin.
Bye,
bearophile
--
http://mail.python.org/mailman/listinfo/python-list
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
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,
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
(and slower).
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
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
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,
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
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
n ShedSkin), so they
are somewhat useful again :-)
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
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
or tools) that
allow to add pre- and post-conditions, class invariants, etc.
Bye,
bearophile
--
http://mail.python.org/mailman/listinfo/python-list
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
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
# 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
000)
> test_func(summer, 1)
> test_func(tupler, 1)
Have you forgotten my function?
Bye,
bearophile
--
http://mail.python.org/mailman/listinfo/python-list
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
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
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
'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
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
he end into a
text file :-)
Bye,
bearophile
--
http://mail.python.org/mailman/listinfo/python-list
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
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
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
inite loop (there's a
compilation flag that avoids some infinite loops, try it).
Bye,
bearophile
--
http://mail.python.org/mailman/listinfo/python-list
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
/cheval/file/46797c3a5136/chevalx.pyx#l1
Bye,
bearophile
--
http://mail.python.org/mailman/listinfo/python-list
iables?
Bye,
bearophile
--
http://mail.python.org/mailman/listinfo/python-list
r DMD compiler):
http://pyd.dsource.org/
Bye,
bearophile
--
http://mail.python.org/mailman/listinfo/python-list
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
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
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
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
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
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
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
ink its name may be changed to Fusil, I
don't know).
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.
B
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
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
e needs, then MatPlotLib can be better.
Bye,
bearophile
--
http://mail.python.org/mailman/listinfo/python-list
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
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
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,
ctional-style programming? Like
creating nested functions on the fly, etc.
Bye,
bearophile
--
http://mail.python.org/mailman/listinfo/python-list
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
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
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
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
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
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
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
;t be certain, you are able reduce the probabilities of some
bugs to happen.
Bye,
bearophile
--
http://mail.python.org/mailman/listinfo/python-list
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.
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
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
97 matches
Mail list logo