Paul McGuire wrote:
> I don't find 'Interval' to be very easy on the eyes. In this case, I
> stole^H^H^H^H^H borrowed the re form of "[A-Za-z0-9]", providing a
> method named srange ("s" is for "string") such that srange("a-fA-F")
> would return the string "abcdefABCDEF".
Thank you for your answ
Peter Hansen>but I'd be happy to see a real-world case where Psyco gave
a much bigger boost.)<
Psyco can be very fast, but:
- the program has to be the right one;
- you have to use "low level" programming, programming more like in C,
avoiding most of the nice things Python has, like list generator
I haven't examined the code very well, but generally I don't suggest to
use exceptions inside tight loops that that have to go fast.
Bye,
bearophile
--
http://mail.python.org/mailman/listinfo/python-list
With your input this returns:
[200, 20, 0, 13050]
so it's not what you want, but maybe it can be a starting point for
you:
from re import findall
txt = """\
test test test description (100-10-0, 6700 test)
test test test description (100-10-0, 6350 test)"""
lines = txt.split("\n")
re
It seems that Java JDK 1.4 (-server) HotSpot compiler sometimes (in
this test, on this computer, etc.) can produce programs faster than C
and Fortran ones in n-body simulations and similar stuff:
http://shootout.alioth.debian.org/gp4/benchmark.php?test=nbody&lang=all
http://shootout.alioth.debian.
A dict can be useful:
byte1, byte2 = 32, 1
conv1 = {(32, 32):0, (36,32):"natural", (32,1):5, (66,32):0.167}
print conv1[byte1, byte2]
If you use Psyco maybe something like this can be faster:
conv2 = dict((k1*256+k2,v) for (k1,k2),v in conv1.items())
print conv2[(byte1<<8) + byte2]
conv1/conv2
This post is about a programming language that I've never used, called
Pliant. Sometimes knowing something about other languages can be useful
for our language, so I think this is not a fully off topic post. Time
ago I have found Python (that now I am using a lot) because I like to
explore less kno
Juho Schultz
>NIR_mean_l only from lines 1, 4, 7, ...
>R_mean_l only from lines 2, 5, 8, ...
>G_mean_l only from lines 3, 6, 9, ...
This can be the problem, but it can be right too.
The following code is shorter and I hope cleaner, with it maybe
Kriston-Vizi Janos can fix his problem.
class ReadD
Well, maybe it's time to add a n-levels flatten() function to the
language (or to add it to itertools). Python is open source, but I am
not able to modify its C sources yet... Maybe Raymond Hettinger can
find some time to do it for Py 2.5.
Bye,
bearophile
--
http://mail.python.org/mailman/listin
Most of my ideas seem usless or stupid, but I think expressing them
here doesn't harm much.
This is an idea for Py 3.0, because it's not backward compatible.
Dicts and sets require immutable keys, like tuples or frozensets, but
to me they look like a duplication. So the idea is to remove tuples an
The first line of that example has to be:
s = |set([1, 3, 5])|
But I don't know/remember why set() can't accept many values like
max/min:
max([1,2,5])
max((1,2,5))
max(1,2,3)
Bye,
bearophile
--
http://mail.python.org/mailman/listinfo/python-list
Raymond Hettinger:
>I'm curious whether you've had an actual use for dictionaries as keys.<
I've never had this need (probably because it's an unsupported thing to
do too).
>Likewise, how about frozensets? Have you had occasion to use them as keys?
>They were created to support sets of sets,
The array module allows you to specify a single type of elements.
Bye,
bearophile
--
http://mail.python.org/mailman/listinfo/python-list
This isn't much tested, so don't trust it much, and I hope it's not
overkill.
You can find Graph here:
http://sourceforge.net/projects/pynetwork/
With this you can plot the tree, if you want:
g.springCoords(); g.plot2d()
Bear hugs,
bearophile
def scan(g, parent):
subs = [scan(g, sub) for sub
Ranges of letters are quite useful, they are used a lot in Delphi/Ada
languages:
"a", "b", "c", "d", "e"...
I like the syntax [1..n], it looks natural enough to me, but I think
the Ruby syntax with ... isn't much natural.
To avoid bugs the following two lines must have the same meaning:
[1..n-1]
[
This is yet another memoize decorator, it's meant to be resilient (and
fast enough):
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/466320
Like most memoize decorators it stores the pairs of data-result in
cache dictionary, but Garrett Rooney says:
it could be better if it used the new w
Sanjay wrote:
> I am new to python. Sorry if this is too novice question,
Don't worry and welcome.
> While coding a business class library, I think it is preferable to have
> one class per source file, rather than combining all classes into one
> file, considering multiple developers developing
It looks like homework. Sometimes the simpler code is better:
def splitter(seq):
if not seq:
return []
result = []
current = [seq[0]]
for pos, el in enumerate(seq[1:]):
if el - current[-1] > 1:
result.append(current[:])
current = []
c
Peter Otten:
> which is almost identical to the last example in
> http://docs.python.org/lib/itertools-example.html
I see, thank you. I haven't had enoug time and brain to fix it (and the
OP question seemed like homework, so leaving some other things to do is
positive).
I think still that too muc
Steve Holden:
> The real problems with the Py3k list seem to be associated with a number
> of people who, despite having had little apparent connection to the
> language until now, have joined the list and started making
> inappropriate suggestions, which then have to be (patiently) rejected.
This
Adam wrote:
> Where should a py newbie start to do some 2D graphs on screen ?
> PythonGraphApi,
> Gato, looks interesting
> pygraphlib,
> matplotlib,
> is there a best native Python place to start ?
The only good and simple way I have found so far to do some free
graphics with Python in a Window i
Pierre Quentel:
> If the line number of the first line is 0 :
> source=open('afile.txt')
> for i,line in enumerate(source):
> if i == line_num:
> break
> print line
I don't know if something like this can be called an improvement:
from itertools import islice
afile = file('data.txt')
Bryan:
> do you think that pygame would be a good alternative to matplotlib to create
> some graphs such simple bar and line graphs?
For graphs MatPlotLib is usually better, and its antialiasing library
(Anti-Grain Geometry) is wonderful. Pygame gives a bit more freedom but
you have to do all for
T wrote:
> Do I need to close the file in this case? Why or why not?
> for line in file('foo', 'r'):
> print line
Close the file in Jython, but often it's not necessary in CPython.
Bye,
bearophile
--
http://mail.python.org/mailman/listinfo/python-list
Dan Bishop:
> xrange already has __contains__. The problem is, it's implemented by a
> highly-inefficient sequential search. Why not modify it to merely
> check the bounds and (value - start) % step == 0?
I think this is a nice idea.
Bye,
bearophile
--
http://mail.python.org/mailman/listinfo/
Volker Grabsch wrote:
> IMHO, that flaw of Python should be documented in a PEP as it violates
> Python's priciple of beeing explicit. It also harms duck typing.
I think this may be good food for Python 3.0, the are removing
undefined comparisons too (>), etc.
bye,
bearophile
--
http://mail.pyt
alfa1234:
> Does anyone know and equalent way to confirm a Variable from the same
> property file using PYTHON code ???
Using globals(), locals(), and dir() you can find if your name exists
already.
Bye,
bearophile
--
http://mail.python.org/mailman/listinfo/python-list
I don't like much the syntax of:
if __name__ == '__main__':
Some time ago I have read this PEP:
http://www.python.org/dev/peps/pep-0299/
And why it was refused:
http://mail.python.org/pipermail/python-dev/2006-March/062955.html
I think the name of the standard main function may be just main(), s
Faulkner:
> http://home.comcast.net/~faulkner612/programming/python/mainer.py
It's a bit of magic, I'll test it more, but it seems to work binding
the main() with Psyco too.
I have changed it a little (removed argv passed to the main and the
import of type, etc).
I don't know if/when I'll use it,
Michael Yanowitz:
> Maybe I am missing something, but from what I've seen,
> it is not possible to overload functions in Python.
Maybe here you can find some ideas:
http://www.artima.com/forums/flat.jsp?forum=106&thread=101605
http://bob.pythonmac.org/archives/2005/03/30/five-minute-multimethods-
Simon Hibbs:
> It seems to me that unless you
> need some of the functionality supplied with dictionaries (len(a),
> has_key, etc) then simple objects are a syntacticaly cleaner and more
> natural way to express yourself.
I'd say the opposite. Classes contain a dict of their attributes, etc.
So if
Aahz, citing Guido:
>__slots__ is a terrible hack with nasty, hard-to-fathom side
>effects that should only be used by programmers at grandmaster and
>wizard levels. Unfortunately it has gained an enormous undeserved
I think I have used __slots__ just one time. Can you tell me some of of
such bad
placid:
This may be a solution:
l1 = ['acXXX1', 'XXX2', 'wXXX3', 'kXXX5']
l2 = [ 'bXXX1', 'xXXX2', 'efXXX3', 'yXXX6', 'zZZZ9']
import re
findnum = re.compile(r"[0-9]+$")
s1 = set(int(findnum.search(el).group()) for el in l1)
s2 = set(int(findnum.search(el).group()) for el in l2)
nmax = max(max(s
Steve Jobless:
> I'm hearing that "they are features, but don't use them."
You can use them if you know why you are doing it.
You can also take a look at PyChecker and PyLint, they may help you.
Bye,
bearophile
--
http://mail.python.org/mailman/listinfo/python-list
Roy Smith:
> 2) I find the "and 1 or 0" part very confusing. I can't remember all the
> minor rules about operator precedence, but I'm sure this works out to some
> clever hack involving boolean short-circuit evaluation to get around the
> lack of a ternary operator in python. If I need to pull o
Pierre Thibault, some people here surely know enough Python (and C++)
to solve your problem, but often the problem is understanding the
problem. I have understood your problem just partially, so the
following are just ideas.
First of all I suggest you to use a normal Python list to keep the
data,
[EMAIL PROTECTED]:
> def f(a, b, c): return a + b + c
> I can do:
> fplus10 = f(10)
> and then call f with 2 params and it works.
If you call that f or that fplus10 with two parameters you obtain an
error in both cases. You have an error with the f(10) line too.
With Python 2.5 you can probably u
The write accepts strings only, so you may do:
out.write( repr(list(clean)) )
Notes:
- If you need the strings in a nice order, you may sort them before
saving them:
out.write( repr(sorted(clean)) )
- If you need them in the original order you need a stable method, you
can extract the relevant co
A possibility:
import os
_, _, file_names = os.walk("").next()
print sorted(file_names, key=lambda fn: os.stat(fn)[8])
Bye,
bearophile
--
http://mail.python.org/mailman/listinfo/python-list
You can use this, fast, gives a tuple:
from Tkinter import _flatten as flatten
---
The xflatten/flatten version I sometimes use, maybe I can put something
similar in the cookbook, but it can be improved a lot (and isrecursive
is too much fragile):
from pprint import isrecurs
[EMAIL PROTECTED]:
> I want to write a program which would have a 2 dimensional array of 1
> billion by 1 billion. This is for computational purposes and evaluating
> a mathematical concept similar to Erdos number.
Maybe you are talking about the edges of a graph with 1e9 nodes. This
structure is
tac-tics:
> If you declare bits in set_bit() as "global bits = ...", it will create
> it as a global variable without you having to declare it outside of the
> function. Just be careful about name conflicts.
Are you sure?
def fun():
global x = 10
fun()
print x
Bye,
bearophile
--
http://mai
[EMAIL PROTECTED]:
> 1- Read the data and put all variables in a list
> 2- Read the data and put all the variables in dictionary?
> the logs is in this format
> xx
> The separation is by byte size like
> xxx three bytes for code x , bytes for hour, etc..
> I have two m
Paul McGuire:
> generation of the railroad diagrams (in something
> more legible/appealing than ASCII-art!).
That ASCII-art looks easy enough to read. It may be bad when the graph
becomes very big.
Bye,
bearophile
--
http://mail.python.org/mailman/listinfo/python-list
sys.maxint gives the largest positive integer supported by Python's
regular integer type. But maybe such attribute, with few others (they
can be called min and max) can be given to int type itself.
D is a very nice language, that I hope to see more used. It is copying
lot of things from Python. D F
Paddy:
> Or do you mean the ability to choose between hardware supported float
> s? e.g. float and double precision?
No, I mean just having the ability to ask the float (his attribute)
what are the max and min values it can represent, etc.
stop = float.max
...
I don't know any simple way to know
Self:
>>D is a very nice language, that I hope to see more used. It is copying
>>lot of things from Python.
Tim Roberts:
>I don't see that. It looks rather like an incremental improvement to C and
>C++ rather than a language influenced by Python.
Thank you for your comments. Mine was probably j
[EMAIL PROTECTED]:
It's not a bug, but such incompatibility problem will probably be
solved with Python 3.0, when most strings will managed as unicode.
The documentation says:
>it returns a copy of the s where all characters have been mapped through the
>given translation table which must be a
Martin Höfling:
> is it possible to put the methods of a class in different files? I just
> want to order them and try to keep the files small.
Well, you can create one or more modules filled with nude methods, and
you can define a class inside another module, and then add the methods
to this last
Jason wrote:
> He points out that if some code gets accidentally dedented, it is
> difficult for another programmer to determine which lines were supposed
> to be in the indented block. I pointed out that if someone
> accidentally moves a curly brace, the same problem can occur.
I like significan
Andre Meyer:
> What is the preferred pythonic way of implementing singleton elegantly?
Maybe to just use a module.
Bye,
bearophile
--
http://mail.python.org/mailman/listinfo/python-list
Jason wrote:
> But newsgroup managers are certainly an issue.
> For comment thingies online, the preformat tag is your friend, too.
Time ago I used to add a | or something similar at the beginning of
lines, to avoid the leading whitespace stripping done by Google Groups.
Other (silly) solutions ar
Simon Forman:
> It's unlikely to
> be deprecated since it doesn't make much sense to make it an attribute
> of the str type.
Why?
Thank you,
bearophile
--
http://mail.python.org/mailman/listinfo/python-list
Simon Forman:
> accessing it from a
> module (perhaps math.. math.infinity, math.epsilon, etc., just like
> math.pi and math.e.)
It too looks acceptable.
> I look forward to hearing your thoughts an the subject.
Thank you, but I am not expert enough on such topics to give you good
comments, s
[EMAIL PROTECTED]:
> Is there
> a way to avoid having to use the "from xxx import yyy" syntax from
> files in the same directory?
You can just use:
import xxx
and then:
class Two(xxx.One):
...
If you don't want to use the import line, you have to put the two
classes into the same module.
By
Justin Azoff:
> It takes a second or two to read the list of words in,
Nice solution. If you want to speed up the initialization phase you may
use something like this (it requires a bit more memory, because lines
contains all the words).
Note that the words and numbers have the same sorting order
Note that this is essentially a data-compression problem, so the most
accurate solution is probably to use an instrumeted PAQ compressor in a
certain smart way, but you have to work a lot to implement this
solution, and maybe this problem doesn't deserve all this work.
Bye,
bearophile
--
http://
I've tested that sorting just the strings instead of the tuples (and
removing the stripping) reduces the running time enough:
def __init__(self):
numbers = '222333444555666888'
conv = string.maketrans(string.lowercase, numbers)
lines =
file("/usr/share/dict/word
John Machin:
> 2. All responses so far seem to have missed a major point in the
> research paper quoted by the OP: each word has a *frequency* associated
> with it. When there are multiple choices (e.g. "43" -> ["he", "if",
> "id", ...]), the user is presented with the choices in descending
> frequ
[EMAIL PROTECTED]:
> my eventual goal is
> to be able to put the pictures on the screen with a full-screen
> interface. Not in a visible window, with just the picture and then a
> black backdrop for it.
Pygame (plus PIL if you need) can do that, Pygame manages full screens
too.
Bye,
bearophile
Yu-Xi Lim:
Thank you for your comments, and sorry for my last cryptic answer.
>I think Bearophile isn't refering to compression of the dictionary, but the
>predictive algorithms used by modern data compressors. However, I think he's
>over-complicating the issue. It is *not* a data compression p
Fuzzydave:
> I am trying to check all of the historyRep items
> to check if they are empty/null/None (whatever the term is in python)
An item can't be empty in Python,and null doesn't exist, it can be the
object None. But probly that's not your case.
> I did print
> historyRep[8] out and it fal
Simon Forman:
> I originally meant this as a joke and was going to say not to use it.
> But on my old, slow computer it only takes about a second or two.
Another possibility, still using a filter:
nodig = set("06789")
r = [i for i in xrange(1, 5+1) if not (set(`i`) & nodig)]
Bye,
bearoph
Stargaming:
> Also note that reduce will be removed in Python 3000.
Then let's use it until it lasts! :-)
bearophile
--
http://mail.python.org/mailman/listinfo/python-list
Gerard Flanagan:
> mod5 = ['1','2','3','4','5']
> X = [ ''.join([a,b,c,d,e])
> for a in mod5
> for b in mod5
> for c in mod5
> for d in mod5
> for e in mod5 ]
A modified version of your one is the faster so far:
v = "12345"
r = [a+b+c+d+e for a in v for b in v for c
Jason Nordwick:
> Stargaming wrote:
> > Also note that reduce will be removed in Python 3000.
> What will replace it?
Nothing, I presume. You will have to write a function to find another
way to solve problems.
Bye,
bearophile
--
http://mail.python.org/mailman/listinfo/python-list
Yi Xing wrote:
> I need to read a large amount of data into a list. So I am trying to
> see if I'll have any memory problem. When I do
> x=range(2700*2700*3) I got the following message:
> Traceback (most recent call last):
> File "", line 1, in ?
> MemoryError
> Any way to get around this pr
[EMAIL PROTECTED] wrote:
> py> def SetNewDataParam2(Data, NewData):
> ... if type(Data[Data.keys()[0]]) == type(dict()):
> ... SetNewDataParam2(Data[Data.keys()[0]], NewData)
> ... else:
> ... Data[Data.keys()[0]] = NewData
> ...
> ... return Data
> py> Data = {'a':{'b':
Like for the list.sort() method, to remind you that this function
operate by side effect, maybe it's better if it doesn't return the
modified nested dict:
def setNested(nest, path, val):
nest2 = nest
for key in path[:-1]:
nest2 = nest2[key]
nest2[path[-1]] = val
Bye,
bearophil
Tim Gallagher:
> I am new to python and I have a few questions. I am an old Perl hacker
> been using Perl for many years. I wanted to give python a try, I am
> happy with it so far.
In some places and jobs Perl is the only scripting language used still,
but It seems there are other people like y
Paul Rubin:
> Sybren Stuvel:
> > Because of "there should only be one way to do it, and that way should
> > be obvious". There are already the str.join and unicode.join methods,
>
> Those are obvious???
They aren't fully obvious (because they are methods of the separator
string), but after reading
Astan Chee:
(This is a small trap of Python, that it shares with some other
languages, and it shows that it may exist a language with a higher
level than Python.)
Generally in Python you can't modify a sequence that you are iterating
on.
There are some ways to avoid the problem. You can create a d
bussiere maillist:
> i've got a very long string
> and i wanted to convert it in binary
Not much tested:
_nibbles = {"0":"", "1":"0001", "2":"0010", "3":"0011",
"4":"0100", "5":"0101", "6":"0110", "7":"0111",
"8":"1000", "9":"1001", "A":"1010", "B":"1011",
I am not expert of REs yet, this my first possible solution:
import re
txt = """
"""
tfinder = r"""<# The opening < the tag to find
\s* # Possible space or newline
(tag[12]) # First subgroup, the identifier, tag1
or tag2
Jiang Nutao:
> To convert list
> aa = [0x12, 0x34, 0x56, 0x78]
> into
> [0x34, 0x12, 0x78, 0x56]
> How to do it fast? My real list is huge.
Note that:
>>> a = range(6)
>>> a
[0, 1, 2, 3, 4, 5]
>>> a[::2]
[0, 2, 4]
>>> a[1::2]
[1, 3, 5]
So you can do:
>>> a[::2], a[1::2] = a[1::2], a[::2
This thread can be useful for ShedSkin (the Python => C++ translator),
because often it manages strings slower than CPython still, some
suggestions from a C++ expert can surely improve things a lot. C++ is
fast, but you have to use and know it well, otherwise you don't obtain
much speed.
Maybe thi
Will McGugan:
> I was wondering if there was a C++ library that
> implemented the fundamental objects of Python as close as possible,
> perhaps using STL underneath the hood.
> Too clarify, Im not looking to interface C++ with Python in any way,
> just to emulate the strings / containers / slicing
Paul Rubin:
> I think the underlying regexp C library isn't written that way. I can
> see reasons to want a higher-level regexp library that works on
> arbitrary sequences, calling a user-supplied function to classify
> sequence elements, the way current regexps use the character code to
> classif
A simple RE engine written in Python can be short, this is a toy:
http://paste.lisp.org/display/24849
If you can't live without the usual syntax:
http://paste.lisp.org/display/24872
Paul Rubin:
> Yes, I want something like that all the time for file scanning without
> having to resort to parser mo
[EMAIL PROTECTED]:
> Is there any library in Python which has implementation of graph
> theoretic algorithms and models ?
There are many of them, like:
https://networkx.lanl.gov/
Mine:
http://sourceforge.net/projects/pynetwork/
...and some other.
Bye,
bearophile
--
http://mail.python.org/mailma
[EMAIL PROTECTED]:
>I was wondering if you can generate random graph and analyze some
> peroperties of it like clustering coefficient or graph density.
There are many kinds of random graphs, in that Graph lib I have added
few random generators, but you can add many more yourself, it's easy
(Then i
Fabian Braennstroem:
> A more difficult log file looks like:
> ...
> With my sed/awk/grep/gnuplot script I would extract the
> values in the 'U-Mom' row using grep and print a certain
> column (e.g. 'Max Res') to a file and print it with gnuplot.
> Maybe I have to remove those '|' using sed before.
[EMAIL PROTECTED]:
> Is there any documentation avaialbe for networkx ? I want to have an
> implementation of random graphs including watts and strogatz graph.
Try reading the code, often it's simple enough.
Bye,
bearophile
--
http://mail.python.org/mailman/listinfo/python-list
Peter Maas:
> I have noticed that in the language shootout at shootout.alioth.debian.org
> the Python program for the n-body problem is about 50% slower than the Perl
> program. This is an unusual big difference. I tried to make the Python program
> faster but without success. Has anybody an explan
[EMAIL PROTECTED] wrote:
> Ah, wait a moment. One more tweak. Make the body class a psyco class.
> That improves the runtime to 3.02s. Diff appended.
Nice. Maybe you can do the same trick with:
from psyco.classes import __metaclass__
If you want you can try that trick with this version of mine
Paddy:
> You might also put the outer loop calling function advance so many
> times, into the advance function:
Remember that the autors of the Shootout refuse some changes to the
code (like this one), to allow a fair comparison. The rules are strict.
I have improved the Psyco version:
http://sho
Tim Chase:
> It still doesn't solve the aforementioned problem
> of things like ')))(((' which is balanced, but psychotic. :)
This may solve the problem:
def balanced(txt):
d = {'(':1, ')':-1}
tot = 0
for c in txt:
tot += d.get(c, 0)
if tot < 0:
return Fal
Fredrik Lundh wrote:
> it's slightly faster, but both your alternatives are about 10x slower
> than a straightforward:
> def balanced(txt):
> return txt.count("(") == txt.count(")")
I know, but if you read my post again you see that I have shown those
solutions to mark ")))(((" as bad expres
[EMAIL PROTECTED]:
Python is strongly typed, and it converts types automatically less
often than Perl.
The purpose of such strong(er) typing is to allow to catch some kind of
bugs, and to make the syntax simpler, more readable, etc.
> message = "abc"
> password = "z12"
> scrambled = message ^ pas
rh0dium:
> This is where $_ in perl is awesome - There must be a default variable
> in python right?
A default variable may add bugs to your code, and newbies of the
language may see it coming from air, so Python avoids such things. The
only Python "default variable" I know of is the _ that when u
I have implemented yet another Odict class:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/498195
It's very slow, but it is O(1) for get, set and del too.
I have added ritervalues(), rkeys(), etc methods because I presume I
can't use the reversed(). So can an __riter__ hook be generally u
John Doty:
> Yes. The efficient exact algorithms for this problem use *partial*
> sorts. The Forth one from the FSL is of this class (although I know of
> two better ones for big arrays). But it's tough to beat the efficiency
> of the approximate histogram-based method the Python stats module
> imp
Marc 'BlackJack' Rintsch:
> I don't know if this is documented somewhere but the `reversed()` function
> looks for a `__reversed__()` method that returns an iterator.
You are right, thank you, I have done some tests already, and I'll soon
add that method too.
---
Partially relat
[EMAIL PROTECTED]:
> 456 ".itervalues()" lang:python
> 415 ".iteritems()" lang:python
> 403 ".iterkeys()" lang:python
> 387 ".values()" lang:python
> 385 ".clear()" lang:python
> 256 ".update(" lang:python
> 254 ".fromkeys(" lang:python
> 224 ".has_key(" lang:python
> 201 ".get(" lang:python
> 200
[EMAIL PROTECTED] wrote:
> no sort() is needed to calculate the median of a list.
> you just need one temp var.
Can you show some actual code?
(There is the median of 5 algorithm too).
Bye,
bearophile
--
http://mail.python.org/mailman/listinfo/python-list
Ian McConnell wrote:
> > If you can use Psyco and your FITS lines are really long (well, maybe
> > too much, the treshold if about >~3000 in my PC) you can use something
> > like this instead the builtin timsort:
> > http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/466330
> > (To compute the
Alexey Borzenkov:
> I was so attached to these "nameless" def-forms that I was even shocked
> when I found that this doesn't work in python:
> f = def(a, b):
> return a*b
> Another good feature of Boo, btw.
I think Boo has some good things worth consideration (and maybe worth
to copy) and so
A pair of solutions:
>>> s = "central_african_republic_province.txt"
>>> s.rsplit("_", 1)[-1].split(".")[0]
'province'
>>> import re
>>> p = re.compile(r"_ ([^_]+) \.", re.VERBOSE)
>>> s = """\
... wisconsin_state.txt
... french_guiana_district.txt
... central_african_republic_province.txt"""
>>>
It looks interesting, PyGegl is a python binding for gegl:
http://ervilha.org/pygegl/
Bye,
bearophile
--
http://mail.python.org/mailman/listinfo/python-list
This part of code uses integer "constants" to be or-ed (or added):
CAPS_FIRST = 1
NUMERICAL = 2
HYPHEN_AS_SPACE = 4
UNDERSCORE_AS_SPACE = 8
IGNORE_LEADING_WS = 16
COMMA_IN_NUMERALS = 32
...
def __init__(self, flag):
self.flag = flag
def transform(self, s):
""" Transform a string for coll
101 - 200 of 1196 matches
Mail list logo