ider that surprising, but maybe I should? (Honest question, I really
don't know.)
--
Wolfram Hinderer
--
https://mail.python.org/mailman/listinfo/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
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
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
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/
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)
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
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
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
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.
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
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
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
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
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
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,
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
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
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
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
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
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(
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
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
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
'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[
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)
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
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
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:
>>
>>
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
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
::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
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
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
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
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
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
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',
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
ib/module-urllib2.html
http://docs.python.org/lib/urllib2-examples.html
HTH,
Wolfram
--
http://mail.python.org/mailman/listinfo/python-list
>
> 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
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.
>
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
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
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
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
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
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
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
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
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
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 (@
d the link to the last flameware about it :-))
--
cu
Wolfram
--
http://mail.python.org/mailman/listinfo/python-list
be
so much easier with python. i dont want to go back to php!
--
cu
Wolfram
--
http://mail.python.org/mailman/listinfo/python-list
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)
>
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
.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
HTML-Page.
HTH,
Wolfram
--
http://mail.python.org/mailman/listinfo/python-list
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
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.
tmode(c, 'open')
root.mainloop()
--8<-- Cut here -----
Can this somehow be done?
TIA,
Wolfram
--
http://mail.python.org/mailman/listinfo/python-list
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
63 matches
Mail list logo