Re: some problems for an introductory python test

2021-08-11 Thread Wolfram Hinderer via Python-list
ider that surprising, but maybe I should? (Honest question, I really don't know.) -- Wolfram Hinderer -- https://mail.python.org/mailman/listinfo/python-list

Re: count consecutive elements

2021-01-14 Thread Wolfram Hinderer via Python-list
Am 13.01.2021 um 22:20 schrieb Bischoop: I want to to display a number or an alphabet which appears mostly consecutive in a given string or numbers or both Examples s= ' aabskaaabad' output: c # c appears 4 consecutive times 8bbakebaoa output: b #b appears 2 consecutive times You can

Re: best way to remove leading zeros from a tuple like string

2018-05-21 Thread Wolfram Hinderer via Python-list
to be even simpler. >>> str(tuple(map(int, s[1:-1].split("," '(128, 20, 8, 255, -1203, 1, 0, -123)' Wolfram -- https://mail.python.org/mailman/listinfo/python-list

Re: N-grams

2016-11-09 Thread Wolfram Hinderer
Am 10.11.2016 um 03:06 schrieb Paul Rubin: This can probably be cleaned up some: from itertools import islice from collections import deque def ngram(n, seq): it = iter(seq) d = deque(islice(it, n)) if len(d) != n: return for s in

Re: find all multiplicands and multipliers for a number

2015-04-11 Thread wolfram . hinderer
Am Samstag, 11. April 2015 09:14:50 UTC+2 schrieb Marko Rauhamaa: > Paul Rubin : > > > This takes about 4 seconds on a Intel(R) Core(TM) i5-3230M CPU @ 2.60GHz > > laptop (64 bit linux): > > Converted to Python3: > > #!/usr/

Re: copy on write

2012-02-06 Thread Wolfram Hinderer
On 3 Feb., 11:47, John O'Hagan wrote: > But isn't it equally true if we say that z = t[1], then t[1] += x is > syntactic sugar for z = z.__iadd__(x)? Why should that fail, if z can handle > it? It's more like syntactic sugar for y = t; z = y.__getitem__(1); z.__iadd__(x); y.__setitem__(1, z)

ipython -wthread vs. ipython -pylab

2011-09-12 Thread Wolfram Brenig
plotlib to mayavi usage? Most likely no. But what should I do? Thanks for your help Wolfram -- http://mail.python.org/mailman/listinfo/python-list

Re: Faster Recursive Fibonacci Numbers

2011-05-17 Thread Wolfram Hinderer
On 17 Mai, 20:56, geremy condra wrote: > On Tue, May 17, 2011 at 10:19 AM, Jussi Piitulainen > > wrote: > > geremy condra writes: > > >> or O(1): > > >> ö = (1 + sqrt(5)) / 2 > >> def fib(n): > >>     numerator = (ö**n) - (1 - ö)**n > >>     denominator = sqrt(5) > >>     return round(numerator/d

Re: How on Factorial

2010-10-30 Thread Wolfram Hinderer
On 27 Okt., 10:27, Arnaud Delobelle wrote: > True.  It's far too verbose.  I'd go for something like: > >     f=lambda n:n<=0 or n*f(~-n) > > I've saved a few precious keystrokes and used the very handy ~- idiom! You can replace "n<=0" with "n<1". Then you can leave out the space before "or" ("0o

Re: default behavior

2010-08-06 Thread Wolfram Hinderer
On 6 Aug., 22:07, John Posner wrote: > On 8/2/2010 11:00 PM, John Posner wrote: > > > On 7/31/2010 1:31 PM, John Posner wrote: > > >> Caveat -- there's another description of defaultdict here: > > >>http://docs.python.org/library/collections.html#collections.defaultdict > > >> ... and it's bogus.

Re: Python -- floating point arithmetic

2010-07-08 Thread Wolfram Hinderer
On 8 Jul., 15:10, Ethan Furman wrote: > Interesting.  I knew when I posted my above comment that I was ignoring > such situations.  I cannot comment on the code itself as I am unaware of > the algorithm, and haven't studied numbers extensively (although I do > find them very interesting). > > So

Re: Python -- floating point arithmetic

2010-07-07 Thread Wolfram Hinderer
On 7 Jul., 19:32, Ethan Furman wrote: > Nobody wrote: > > On Wed, 07 Jul 2010 15:08:07 +0200, Thomas Jollans wrote: > > >> you should never rely on a floating-point number to have exactly a > >> certain value. > > > "Never" is an overstatement. There are situations where you can rely > > upon a fl

Re: Composition of functions

2010-07-01 Thread Wolfram Hinderer
On 1 Jul., 06:04, Stephen Hansen wrote: > The 'reversed' and 'sorted' functions are generators that lazilly > convert an iterable as needed. 'sorted' returns a new list (and is not lazy). -- http://mail.python.org/mailman/listinfo/python-list

Re: Fastest way to calculate leading whitespace

2010-05-09 Thread Wolfram Hinderer
On 8 Mai, 21:46, Steven D'Aprano wrote: > On Sat, 08 May 2010 12:15:22 -0700, Wolfram Hinderer wrote: > > Returning s[:-1 - len(t)] is faster. > > I'm sure it is. Unfortunately, it's also incorrect. > However, s[:-len(t)] should be both faster and correct. Ou

Re: Fastest way to calculate leading whitespace

2010-05-08 Thread Wolfram Hinderer
On 8 Mai, 20:46, Steven D'Aprano wrote: > def get_leading_whitespace(s): >     t = s.lstrip() >     return s[:len(s)-len(t)] > > >>> c = get_leading_whitespace(a) > >>> assert c == leading_whitespace > > Unless your strings are very large, this is likely to be faster than any > other pure-Python

Re: Traversing through variable-sized lists

2010-02-17 Thread Wolfram Hinderer
On 17 Feb., 19:10, Andrej Mitrovic wrote: > Hi, > > I couldn't figure out a better description for the Subject line, but > anyway, I have the following: > > _num_frames = 32 > _frames = range(0, _num_frames) # This is a list of actual objects, > I'm just pseudocoding here. > _values = [0, 1, 2, 3,

Re: Performance of lists vs. list comprehensions

2010-01-19 Thread Wolfram Hinderer
On 19 Jan., 21:06, Gerald Britton wrote: > [snip] > > > > > Yes, list building from a generator expression *is* expensive. And > > join has to do it, because it has to iterate twice over the iterable > > passed in: once for calculating the memory needed for the joined > > string, and once more to

Re: Performance of lists vs. list comprehensions

2010-01-19 Thread Wolfram Hinderer
On 19 Jan., 16:30, Gerald Britton wrote: > >>> Timer("' '.join([x for x in l])", 'l = map(str,range(10))').timeit() > > 2.9967339038848877 > > >>> Timer("' '.join(x for x in l)", 'l = map(str,range(10))').timeit() > > 7.2045478820800781 [...] > 2. Why should the "pure" list comprehension be slow

Re: Writing a string.ishex function

2010-01-14 Thread Wolfram Hinderer
On 14 Jan., 19:48, MRAB wrote: > Arnaud Delobelle wrote: > > "D'Arcy J.M. Cain" writes: > > >> On Thu, 14 Jan 2010 09:07:47 -0800 > >> Chris Rebert wrote: > >>> Even more succinctly: > > >>> def ishex(s): > >>>     return all(c in string.hexdigits for c in s) > >> I'll see your two-liner and rai

Re: Dangerous behavior of list(generator)

2010-01-01 Thread Wolfram Hinderer
foo in foos if foo.bar): foo = (foo for foo in foos if foo.bar).next() iterates twice over (the same first few elements of) foos, which should take about twice as long as iterating once. The lazyness of "any" does not seem to matter here. Of course, you're right that the iteration might or might not be the bottleneck. On the other hand, foos might not even be reiterable. > If the foo items are arbitrary objects which have an equal chance of > being considered true or false, then on average it will have to look at > half the list, By which definition of chance? :-) Wolfram -- http://mail.python.org/mailman/listinfo/python-list

Re: unpacking vars from list of tuples

2009-09-15 Thread Wolfram Hinderer
On 15 Sep., 23:51, Ross wrote: > If I have a list of tuples: > >    k=[("a", "bob", "c"), ("p", "joe", "d"), ("x", "mary", "z")] > > and I want to pull the middle element out of each tuple to make a new > list: > > myList = ["bob", "joe", "mary"] if a tuple is OK: zip(*k)[1] -- http://mail.pyth

Re: Turtle Graphics are incompatible with gmpy

2009-08-05 Thread Wolfram Hinderer
On 5 Aug., 21:31, Mensanator wrote: > > >>> import turtle > >>> tooter = turtle.Turtle() > >>> tooter.tracer > > Traceback (most recent call last): >   File "", line 1, in >     tooter.tracer > AttributeError: 'Turtle' object has no attribute 'tracer'>>> > tooter.hideturtle() > >>> tooter.speed(

Re: Self function

2009-05-05 Thread wolfram . hinderer
On 5 Mai, 08:08, Steven D'Aprano wrote: > Self-reflective functions like these are (almost?) unique in Python in > that they require a known name to work correctly. You can rename a class, > instance or module and expect it to continue to work, but not so for such > functions. When editing source

Re: Functional schmunctional...

2009-02-11 Thread wolfram . hinderer
On 10 Feb., 21:28, r0g wrote: > def inet2ip(n, l=[], c=4): >   if c==0: return ".".join(l) >   p = 256**( c-1 ) >   l.append( str(n/p) ) >   return inet2ip( n-(n/p)*p, l, c-1 ) > The results for 1 > iterations of each were as follows... > > 0.113744974136 seconds for old INET->IP method > 27

Re: seemingly simple list indexing problem

2008-07-30 Thread wolfram . hinderer
ce: >>> sorted(range(len(s)), key=sorted(range(len(s)), >>> key=s.__getitem__).__getitem__) [2, 0, 1] Wolfram -- http://mail.python.org/mailman/listinfo/python-list

Re: substitution of list elements

2008-07-18 Thread Wolfram Kraus
'd', 't', 'e'], ['8', 'g', 'q', 'f']] list5 = ['1', '2', '3'] for j in list4: for k in list5: for i,k in enumerate(list5): if j[0] == k: k = j[3] list5[i] = j[

Re: Can this program be shortened? Measuring program-length?

2008-07-10 Thread wolfram . hinderer
On 10 Jul., 21:57, "r.e.s." <[EMAIL PROTECTED]> wrote: > Can the following program be shortened? ... > > def h(n,m): > E=n, > while (E!=())*m>0:n=h(n+1,m-1);E=E[:-1]+(E[-1]>0)*(E[-1]-1,)*n > return n > h(9,9) > Some ideas... # h is your version def h(n,m): E=n, while (E!=())*m>0:n=h(n+1,m-1)

Re: Indentation and optional delimiters

2008-02-26 Thread wolfram . hinderer
lo=0, hi=None): > if hi is None: > hi = len(a) > #} > while lo < hi: > mid = (lo + hi) // 2 > if x < a[mid]: > hi = mid > #} > else: > lo = mid+1 > #} > #} > a.insert(lo, x) > #} > > And build the original Python code (it's possible to do the opposite > too, but it requires a bit more complex script). Have a look at Tools/Scripts/pindent.py -- Wolfram -- http://mail.python.org/mailman/listinfo/python-list

Re: Just for fun: Countdown numbers game solver

2008-02-17 Thread wolfram . hinderer
ms]: result.update(d[s]) results[nums] = len(result) results100[nums] = len([x for x in result if x >= 100]) # Prevent MemoryError if i % 200 == 0: d.clear() print "Goals: all integers" print_max(results) print print "Goals: integers >= 100" print_max(results100) -- Wolfram -- http://mail.python.org/mailman/listinfo/python-list

Re: merits of Lisp vs Python

2006-12-09 Thread Wolfram Fenske
Steven D'Aprano <[EMAIL PROTECTED]> schreibt: > On Sat, 09 Dec 2006 14:00:10 +, Timofei Shatrov wrote: > >> On Sat, 09 Dec 2006 20:36:02 +1100, Steven D'Aprano >> <[EMAIL PROTECTED]> tried to confuse everyone with this >> message: >> >>

Re: merits of Lisp vs Python

2006-12-08 Thread Wolfram Fenske
easy to use as the system Common Lisp already provides. Stuff like this is impossible in other languages. To summarize: Lispers are not fanatics. And if we appear to be then it is simply because we recognize that Lisp truly is The Chosen Language. [1] Footnotes: [1] Kidding! :-) ... or am I? -- Wolfram Fenske A: Yes. >Q: Are you sure? >>A: Because it reverses the logical flow of conversation. >>>Q: Why is top posting frowned upon? -- http://mail.python.org/mailman/listinfo/python-list

Re: Error handling. Python embedded into a C++ app.

2006-12-02 Thread Wolfram
w, even if with a kludge (I always need to have a console, even if I do not use Python). Bye bye, Wolfram Kuss. -- http://mail.python.org/mailman/listinfo/python-list

Re: Error handling. Python embedded into a C++ app.

2006-11-29 Thread Wolfram
::MessageBox(0, "exception", "", 0 ); } -- snip - I call this where "p" is an "execute" of a *.py file containing an error. I get the "Error in Python call!", but not the "exception". Any help, including links to information, welcome. TIA, Wolfram Kuss. -- http://mail.python.org/mailman/listinfo/python-list

Error handling. Python embedded into a C++ app.

2006-11-28 Thread Wolfram
here is a difference between them? Sorry for the newbie questions but neither a look into my Python-book nor onto google helped. Bye bye, Wolfram Kuss. -- http://mail.python.org/mailman/listinfo/python-list

Re: Sorted list - how to change it

2006-11-09 Thread Wolfram Kraus
you for help > L. > use random.shuffel: >>> import random >>> x = [1,2,3,4,5] >>> random.shuffle(x) >>> x [1, 4, 2, 3, 5] >>> random.shuffle(x) >>> x [4, 2, 1, 3, 5] see: http://docs.python.org/lib/module-random.html HTH, Wolfram -- http://mail.python.org/mailman/listinfo/python-list

Re: looping question 4 NEWB

2006-07-06 Thread Wolfram Kraus
data.replace(i[0],i[1]) > > is there a faster way of implementing this? Also, does the if clause > increase the speed? > > Thanks, > Matthew > >>> import string >>> data='asdfbasdf' >>> data.translate(string.maketrans('asx', 'fgy')) 'fgdfbfgdf' HTH, Wolfram -- http://mail.python.org/mailman/listinfo/python-list

Re: How to measure execution time of a program

2006-06-28 Thread Wolfram Kraus
est way to do it (some code snippet that >> could be included in the program's main function) ?? >> >> Thanks, >> girish >> -- >> http://mail.python.org/mailman/listinfo/python-list >> > Use the Python profiler: http://docs.python.org/lib/profile.html HTH, Wolfram -- http://mail.python.org/mailman/listinfo/python-list

Re: MySQL

2006-02-16 Thread Wolfram Kraus
rodmc wrote: > I need to write a Python application which connects to a MySQL 5.0 > database. Can anyone point me in the right direction or a compatible > library? > > Best, > > rod > See http://sourceforge.net/projects/mysql-python HTH, Wolfram -- http://mail.pyt

Re: How to creat a file?

2005-12-02 Thread Wolfram Kraus
sandorf wrote: > I'm new to python. Have a simple question. > > "open" function can only open an existing file and raise a IOerror when > the given file does not exist. How can I creat a new file then? > open the new file in write mode: open('foo', &#x

Re: How to use a timer in Python?

2005-09-22 Thread Wolfram Kraus
sfer.lock' is still there? > > I want to do something like this: > > import os > if 'transfer.lock' in os.listdir('/temp'): > # ...wait 10 seconds and then check again if > # 'transfer.lock' is in os.listdir('/temp') > else: > # create 'newfile' > > > Nico import time time.sleep(10) For more information: help(time.sleep) ;-) HTH, Wolfram -- http://mail.python.org/mailman/listinfo/python-list

Re: Retrieving and saving images from internet address

2005-07-25 Thread Wolfram Kraus
ib/module-urllib2.html http://docs.python.org/lib/urllib2-examples.html HTH, Wolfram -- http://mail.python.org/mailman/listinfo/python-list

Re: Replacing last comma in 'C1, C2, C3' with 'and' so that it reads 'C1, C2 and C3'

2005-07-11 Thread Wolfram Kraus
> > Regards and sorry for the newbie question, > > Ric > > Use rfind and slicing: >>> x = "C1, C2, C3" >>> x[:x.rfind(',')]+' and'+x[x.rfind(',')+1:] 'C1, C2 and C3' HTH, Wolfram -- http://mail.python.org/mailman/listinfo/python-list

Re: need help with MySQLdb

2005-06-30 Thread Wolfram Kraus
database for xampp got a different name. (I am no >> xampp expert, so I can't help you any further) >> >> HTH, >> Wolfram >> >> > after i entered the password it told me it cannot connect to mysql through > socket /tmp/mysql.sock > > hmmmm. >

Re: need help with MySQLdb

2005-06-29 Thread Wolfram Kraus
bases; If MyDB isn't in the list either something went wrong with the xampp installation or the database for xampp got a different name. (I am no xampp expert, so I can't help you any further) HTH, Wolfram -- http://mail.python.org/mailman/listinfo/python-list

Re: catch argc-argv

2005-06-19 Thread Wolfram Kraus
ython API containe fonctions like > 'get_argc()' and 'get_argv()' ? > > Thanks, > > > Use sys.argv: http://python.org/doc/2.4.1/lib/module-sys.html HTH, Wolfram -- http://mail.python.org/mailman/listinfo/python-list

Re: What's wrong with Zope 3 ?

2005-06-02 Thread Wolfram Kraus
Kay Schluehr wrote: > > Wolfram Kraus wrote: > >> Kay Schluehr wrote: >> >>> The last downloadable release is from november 2004. The Windows >>> installer is configured for Python 2.3(!). The Zope.org main page >>> announces Zope 2.8 beta 2. Is

Re: What's wrong with Zope 3 ?

2005-05-31 Thread Wolfram Kraus
information page: "Zope X3 3.0 is for developers. If you are expecting an end-user application, this is not for you." The current stable brance is Zope2.X If you want to incorporate some functionalty from X3 in Zope 2.X, do a search for "Five" HTH, Wolfram -- http://mail.python.org/mailman/listinfo/python-list

Re: Incrementing letters

2005-05-27 Thread Wolfram Kraus
CDEFGHIJKLMNOPQRSTUVWXYZA') > >>>>string.translate("I've got a string s", upone) > > "J'wf hpu b tusjoh t" > > > Note the difference though: the Python code does what you said you wanted, > whereas your sample code co

Re: Strings for a newbie

2005-05-27 Thread Wolfram Kraus
print before the split to see what l[x] is. Oh, and no need for range here, if l is a list: for x in l: print x h = x.split() HTH, Wolfram -- http://mail.python.org/mailman/listinfo/python-list

Re: Incrementing letters

2005-05-27 Thread Wolfram Kraus
he assumption that only characters from a-z are given) he might even try a lil LC: >>> s = "shiftthis" >>> ''.join([chr(((ord(x)-ord('a')+1)%26)+ord('a')) for x in s]) 'tijguuijt' HTH, Wolfram -- http://mail.python.org/mailman/listinfo/python-list

Re: Strings for a newbie

2005-05-27 Thread Wolfram Kraus
an array a() containing the words of the sentence. > > Now can I see how this is done in Python? - nope! > > UGH! > > Malcolm > (a disillusioned Python newbie) > > Use split: >>> s = "This is a sentence of words" >>> s.split() ['This

Re: doc tags?

2005-05-13 Thread Wolfram Kriesing
which might make it into the standard lib, to be available like the doc-string also inside the code - i really like the __doc__) -- cu Wolfram On 5/13/05, Fredrik Lundh <[EMAIL PROTECTED]> wrote: > Wolfram Kriesing wrote: > > > i was already searching and remember i had seen

Re: doc tags?

2005-05-13 Thread Wolfram Kraus
Wolfram Kriesing wrote: > i was already searching and remember i had seen something like "its not > needed". > > Anyway, are there any doc tags, like in Java/PHPDoc etc, where you can > describe parameters (@param[eter]), return values (@ret[urn]), > attributes (@

doc tags?

2005-05-13 Thread Wolfram Kriesing
d the link to the last flameware about it :-)) -- cu Wolfram -- http://mail.python.org/mailman/listinfo/python-list

Re: function with variable arguments

2005-05-13 Thread Wolfram Kriesing
be so much easier with python. i dont want to go back to php! -- cu Wolfram -- http://mail.python.org/mailman/listinfo/python-list

Re: function with variable arguments

2005-05-13 Thread Wolfram Kriesing
i am sure :-) -- cu Wolfram On 13 May 2005 02:52:34 -0700, Xah Lee <[EMAIL PROTECTED]> wrote: > i wanted to define a function where the number of argument matters. > Example: > > def Range(n): > return range(n+1) > > def Range(n,m): > return range(n,m+1) >

Re: What's this error then?

2005-05-02 Thread Wolfram Kraus
l > > os.execl ('/home/sara/PYTHON/HEADER/msgfmt.py', > 'file-roller.HEAD.fa.po') > > > But when I run it, this Error raises: > [EMAIL PROTECTED] HEADER]$ python run.py > /usr/bin/env: python2.2: No such file or directory > > Do you have any solutions? HTH, Wolfram -- http://mail.python.org/mailman/listinfo/python-list

Re: Writing to stdout and a log file

2005-04-20 Thread Wolfram Kraus
.stdout.write() but that doesn't seem to be happening. Any idea what's going one? Or ideas on how to debug this? Thanks, Mike I had the same problem (writing to file and stdout with print) and my solution was *not* to subclass file and instead add a self.outfile=file(...) to the constructor. HTH, Wolfram -- http://mail.python.org/mailman/listinfo/python-list

Re: display VARCHAR(mysql) and special chars in html

2005-02-23 Thread Wolfram Kraus
HTML-Page. HTH, Wolfram -- http://mail.python.org/mailman/listinfo/python-list

Re: python-2.4.msi installation issue

2005-02-03 Thread Wolfram Kraus
rematurely? I have the same problem and don't know what's happening, but ActivePython worked for me. Get it here: http://activestate.com/Products/ActivePython/ HTH, Wolfram -- http://mail.python.org/mailman/listinfo/python-list

Re: how to pass attribute name via sys.argv

2005-01-27 Thread Wolfram Kraus
I have is something like attrName = sys.argv[1] attrName 'cellsize' and I need to pass it on so I can call value = object.cellsize[0] Use getattr: value = getattr(object, attrName)[0] Can this be done using Python? Thanks for any hints Cheers Felix HTH, Wolfram -- http://mail.python.

Associate objects with Tix.Tree

2005-01-15 Thread Wolfram Kraus
tmode(c, 'open') root.mainloop() --8<-- Cut here ----- Can this somehow be done? TIA, Wolfram -- http://mail.python.org/mailman/listinfo/python-list

Re: SuSE 9.1: updating to python-2.4

2005-01-10 Thread Wolfram Kraus
om the shell. If this is version 2.3 you can start 2.4 with "python2.4" All the installed packages for python2.3 (e.g. PIL, MySQLdb, wxPython, ...) need to be installed for the new version, too. Thanks for any hints, Torsten. HTH, Wolfram -- http://mail.python.org/mailman/listinfo/python-list