A few suggestions
Hi.
Just a few "gotcha" suggestions from my personal collection ^^
Tell me which ones are worth a PR:
i = 0; a = ['', '']
i, a[i] = 1, 10
print a # -> ['', 10] - cf. https://news.ycombinator.com/item?id=8091943 - Original blog post from http://jw2013.github.io
issubclass(list, object) # True
issubclass(object, collections.Hashable) # True
issubclass(list, collections.Hashable) # False - There are 1449 such triplets (4.3% of all eligible triplets) in Python 2.7.3 std lib
# Python 2 only, found it myself
f = 100 * -0.016462635 / -0.5487545 # observed on the field, in a real-world situation
print ' f:', f # 3.0
print ' int(f):', int(f) # 2
print ' floor(f):', floor(f) # 2.0
# Name mangling:
class Yo(object):
def __init__(self):
self.__bitch = True
Yo().__bitch # AttributeError: 'Yo' object has no attribute '__bitch'
Yo()._Yo__bitch # True
class O(object): pass
O() == O() # False
O() is O() # False
hash(O()) == hash(O()) # True !
id(O()) == id(O()) # True !!!
# ANSWER: http://stackoverflow.com/a/3877275/636849
json.loads('[NaN]') # [nan]
json.loads('[-Infinity]') # [-inf]
int('١٢٣٤٥٦٧٨٩') # 123456789 - cf. http://chris.improbable.org/2014/8/25/adventures-in-unicode-digits/
# Implicit type conversion of keys in dicts
d = {'a':42}
print type(d.keys()[0]) # str
class A(str): pass
a = A('a')
d[a] = 42
print d # {'a':42}
print type(d.keys()[0]) # str
# Those final ones are taken from cosmologicon Python wats quiz
'abc'.count('') == 4
1000000 < '' and () > [] # "objects of different types except numbers are ordered by their type names"
False == False in [False]
[3,2,1] < [1,3] # False
[1,2,3] < [1,3] # True
x, y = (0, 1) if True else None, None # -> ((0, 1), None)
x, y = (0, 1) if True else (None, None) # -> (0, 1)