Planning to figure out problems of Python that confused me for a long phase.
The blog trace the steps of my study.
Official explain about this build-in function: https://docs.python.org/3/library/functions.html#int
Just found out that there is an arguement called
base, e.g., int('010', 2).
In the past, when I was handling the value of form from user in web application, the program was quite not robust. For example, the program will easily crash if user input twelve in the register form of age.
So exception could be used to solve this problem:
filter a list:
In : list(filter(lambda x:x>0, a))
In Python 2.x,
filter returned a list, but in Python 3.x, it returns an iterator.
In : [i for i in l if i>0]
filter a dict:
from random import randint
random.randint(a, b): Return a random integer N such that a <= N <= b. Alias for randrange(a, b+1).
filter a set:
1. global variable:
NAME, AGE, EMAIL = range(3)
from collections import namedtuple
Sorting a dictionary by value:
sorted(data.items(), key=lambda x:x, reverse=True)
Finding matching keys of dictionaries
from random import randint, sample
In : l = 'abcdefg'