New submission from David Albert Torpey :
Dictionary keys are commonly numbers, strings, or tuples. Python has optimized
numbers and strings to remember their hash values on successive calls. Tuples
should do this too since their recursive hash function can take a long time to
compute. Tuples
New submission from David Albert Torpey :
Floats have fromhex() and hex() to round-trip from and to hexadecimal, but
bytes only have fromhex(), so it's hard to reliably round-trip.
--
messages: 132892
nosy: dtorp
priority: normal
severity: normal
status: open
title: bytes.hex()
New submission from David Albert Torpey :
I would like to left and right shift floats as a fast way to multiply or divide
by a power of 2 without rounding error. The only way to do that now is
t=frexp(x) and y=ldexp(t[0],t[1]+2). But would be better to type y=x<<2.
Tha
David Albert Torpey added the comment:
> sorted(tree, cmp=lambda x, y: 1 if x in tree[y] else -1 if y in tree[x] else
> 0)
>
> and it gets ['A', 'C', 'B', 'E', 'D'].
That cmp function is nonsense and isn't even close to b
New submission from David Albert Torpey :
The purpose of the start argument in str.find() and str.rfind() is to allow for
repeated searches.
>>> def find_third_occurrence(s, value):
... p = s.find(value)
... p = s.find(value, p+1)
... return s.find(v
New submission from David Albert Torpey:
Add a factorial method. Everybody understands what it means before
they are out of high school and it comes up all the time in statistics
and combinatorics. Ruby has a factorial method and heck even basic
calculators have a factorial key.
print
David Albert Torpey added the comment:
Mr. Dickinson thank you for doing this. I do not know how to help with
a patch. If it helps, here is the code I use in python:
def factorial(n, _known=[1]):
assert isinstance(n, int), "Need an integer. This isn't a gamma"
assert
New submission from David Albert Torpey :
$ python3.5
Python 3.5.3 (v3.5.3:1880cb95a742, Jan 16 2017, 08:49:46)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>