Posts
read more
Python
Consider the following code:
funs = [lambda: i for i in range(3)]
print([f() for f in funs])The result it [2,2,2].
funs = [lambda i=i:i for i in range(3)]
print([f() for f in funs])or
funs = (lambda: i for i in range(3))
print([f() for f in funs])The result is [1,2,3].
def f(n, lst=[]):
lst.append(n)
return lst
print(f(1), f(2))The result is [1,2], [1,2].
Posts
read more
About JSON
JSON is the abbreviation for javascript object notation. It defines six data types, namely:
- number
- null
- boolen
- string
- object
- array
Serialize and deserialize json are quite common in programming. For example, we may want to handle the HTTP response from the RESTful APIs, or send a HTTP request.
In Python, the built-in serialize functions are json.dump(), json.dumps(), and deserialize functions
are json.load() and json.loads(). Usually, we represent the json object as a dict in Python.