Skip to content

Instantly share code, notes, and snippets.

View ishashankkumar's full-sized avatar

Shashank Kumar ishashankkumar

View GitHub Profile
>>> a = 593
>>> sys.getrefcount(a)
2
>>> c=a
>>> sys.getrefcount(a)
3
>>> d=a
>>> sys.getrefcount(a)
4
>>>
>>> x=5
>>> dir(x)
['__abs__', '__add__', '__and__', '__class__', '__cmp__', '__coerce__', '__delattr__', '__div__', '__divmod__', '__doc__', '__float__', '__floordiv__', '__format__', '__getattribute__', '__getnewargs__', '__hash__', '__hex__', '__index__', '__init__', '__int__', '__invert__', '__long__', '__lshift__', '__mod__', '__mul__', '__neg__', '__new__', '__nonzero__', '__oct__', '__or__', '__pos__', '__pow__', '__radd__', '__rand__', '__rdiv__', '__rdivmod__', '__reduce__', '__reduce_ex__', '__repr__', '__rfloordiv__', '__rlshift__', '__rmod__', '__rmul__', '__ror__', '__rpow__', '__rrshift__', '__rshift__', '__rsub__', '__rtruediv__', '__rxor__', '__setattr__', '__sizeof__', '__str__', '__sub__', '__subclasshook__', '__truediv__', '__trunc__', '__xor__', 'bit_length', 'conjugate', 'denominator', 'imag', 'numerator', 'real']
>>> x.__str__()
'5'
import dis
print dis.dis(test_one_line_expression)
2 0 LOAD_FAST 1 (b)
3 LOAD_CONST 1 (1)
6 BINARY_ADD
7 LOAD_FAST 0 (a)
10 LOAD_FAST 1 (b)
13 BINARY_ADD
14 ROT_TWO
15 STORE_FAST 0 (a)
>>> def test_one_line_expression(a,b):
... a,b = a+b, b+1
... return a,b
...
>>> print test_one_line_expression(5,6)
(11, 7)
>>> def test_one_line_expression(a,b):
... a,b = b+1, a+b
... return a,b
>>> test_one_line_expression(5,6)
(7, 11)
#!/usr/bin/python
a = 5
b = 7
a,b = a+1, a+b
print a,b
# This is not my solution, the snippet is copied from the link below.
# https://leetcode.com/problems/check-if-it-is-a-good-array/discuss/419368/JavaC%2B%2BPython-Chinese-Remainder-Theorem
def isGoodArray(self, A):
gcd = A[0]
for a in A:
while a:
gcd, a = a, gcd % a
return gcd == 1