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
Am 21.05.2018 um 01:16 schrieb bruceg113...@gmail.com:
If I decide I need the parentheses, this works.
"(" + ",".join([str(int(i)) for i in s[1:-1].split(",")]) + ")"
'(128,20,8,255,-1203,1,0,-123)'
Thanks,
Bruce
Creating the tuple seems to be even simpler.
>>> str(tuple(map(int, s[1:-1].s
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)
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
On 1 Jan., 02:47, Steven D'Aprano wrote:
> On Thu, 31 Dec 2009 11:34:39 -0800, Tom Machinski wrote:
> > On Wed, Dec 30, 2009 at 4:01 PM, Steven D'Aprano
> > wrote:
> >> On Wed, 30 Dec 2009 15:18:11 -0800, Tom Machinski wrote:
> >>> Bottom line, I'm going to have to remove this pattern from my c
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
On 29 Jul., 01:05, Raymond Hettinger <[EMAIL PROTECTED]> wrote:
> [Ervan Ensis]
>
> > I have a list like [108, 58, 68]. I want to return
> > the sorted indices of these items in the same order
> > as the original list. So I should return [2, 0, 1]
>
> One solution is to think of the list indexes
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)
On 26 Feb., 14:36, [EMAIL PROTECTED] wrote:
> A possible solution to this problem is "optional delimiters". What's
> the path of less resistance to implement such "optional delimiters"?
> Is to use comments. For example: #} or #: or something similar.
> If you use such pairs of symbols in a systema
On 22 Jan., 23:56, [EMAIL PROTECTED] wrote:
> So anyone got an answer to which set of numbers gives the most targets
> from 100 onwards say (or from 0 onwards)? IsPythonupto the task?
It's (5, 8, 9, 50, 75, 100): 47561 targets altogether (including
negative ones), 25814 targets >= 100.
(BTW, 1226
27 matches
Mail list logo