Skip to content

Repository files navigation

methodfinder

Python tool to find a method that you know must exist.

Sometimes you know the inputs and outputs for a procedure, but you don't remember the name. methodfinder.find tries to find the name.

>>>importmethodfinder>>>methodfinder.find([]) ==0len([])
sum([])
>>>'a'+5Traceback (mostrecentcalllast):
File"<stdin>", line1, in<module>TypeError: canonlyconcatenatestr (not"int") tostr>>>methodfinder.find('a') ==97# 'a' is 97 in ASCIIord('a')
>>>methodfinder.find(97) =='a'chr(97)
>>>defascii_add(letter, offset):
... returnchr(ord(letter) +offset)
...
>>>ascii_add('a', 5)
'f'>>>methodfinder.find([]) ==Falseany([])
bool([])
callable([])
>>>methodfinder.find(3) =="3"ascii(3)
format(3)
repr(3)
str(3)
>>>methodfinder.find([1,2,6,7], 6) ==True6in [1, 2, 6, 7]
# to use the "in" syntax with your own type, override __contains__>>>methodfinder.find(" ",["foo", "bar"]) =="foo bar"' '.join(['foo', 'bar'])
>>>methodfinder.find([1,2,3]) ==6sum([1, 2, 3])
>>>methodfinder.find([1,2,3]) ==7>>>methodfinder.find('1 + 1') ==2eval('1 + 1')
>>>methodfinder.find(0) ==10.denominatormath.factorial(0)
>>>methodfinder.find(0.0) ==1.0math.cos(0.0)
math.cosh(0.0)
math.erfc(0.0)
math.exp(0.0)
>>>importnumpyasnp>>>methodfinder.find(np, 3) ==np.array([[1.0, 0.0, 0.0], [0.0, 1.0, 0.0], [0.0, 0.0, 1.0]])
numpy.eye(3)
numpy.identity(3)
>>>methodfinder.find([1,2]) == [[1,2],[2,1]]
itertools.permutations([1, 2])
>>>methodfinder.find([1,2], [3,4]) == [[1,3],[2,4]]
itertools.zip_longest([1, 2], [3, 4])
zip([1, 2], [3, 4])
>>>methodfinder.find([1,2], lambdax, y: x+y) ==3functools.reduce(<function<lambda>at0x7f3ac6cc8dd0>, [1, 2])
>>>methodfinder.find(-1,3) ==2-1%3-1+33+-1>>>methodfinder.find(3,2) ==1.53/2>>>methodfinder.find(-1) ==1-(-1)
-1.bit_length()
-1.denominatorabs(-1)
>>>methodfinder.find(1,2) ==31+21^21|22+12^12|1>>>methodfinder.find(1,1) ==11&11**11*11.__class__(1)
1.denominator1.numerator1.real1//11|1math.gcd(1, 1)
max(1, 1)
min(1, 1)
pow(1, 1)
round(1, 1)
>>>methodfinder.find([1,2], '__iter__') ==Truehasattr([1, 2], '__iter__')

About

Python tool to help you find a method that you know likely already exists, but that you can't name.

Resources

Stars

23 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages