5]: def check(x):
In [#### note here : range(len(x)-1,-1, -1
# (end at idx = -1)
for i in range(len(x)-1,-1, -1):
...: #print (x[i])
...: print (i)
...:
...:
...:= "332"
...: x
...: check(x)2
1
0
# LC 138
#-------------------------------------------------
# CASE 1) assignment : point to the same instance
#-------------------------------------------------
112]: z = [1,2,3]
In [
113]: x = y = z
In [
114]: x
In [114]: [1, 2, 3]
Out[
115]: y
In [115]: [1, 2, 3]
Out[
116]: z
In [116]: [1, 2, 3]
Out[
117]: z.append(4)
In [
118]: z
In [118]: [1, 2, 3, 4]
Out[
119]: x
In [119]: [1, 2, 3, 4]
Out[
120]: y
In [120]: [1, 2, 3, 4]
Out[
121]: z
In [121]: [1, 2, 3, 4]
Out[
#-------------------------------------------------
# CASE 2) shallow copy : copy "parent" instance, but NOT sub instance
#-------------------------------------------------
# https://docs.python.org/zh-tw/3/tutorial/datastructures.html
# form 1
a.copy()
# form 2
a[:]
# demo
90]: x = [1,2,3]
In [
91]: y = x[:]
In [
92]: y
In [92]: [1, 2, 3]
Out[
93]: x.append(4)
In [
94]: x
In [94]: [1, 2, 3, 4]
Out[
96]: y
In [96]: [1, 2, 3]
Out[
# LC 77 Combinations
class Solution(object):
def combine(self, n, k):
= []
result
def dfs(current, start):
if(len(current) == k):
result.append(current[:])return
for i in range(start, n + 1):
current.append(i)+ 1)
dfs(current, i
current.pop()
1)
dfs([], return result
#-------------------------------------------------
# CASE 3) deep copy : copy "parent" instance, AND sub instance
#-------------------------------------------------
import copy
25]: import copy
In [
...:= [1,2,3]
...: x = copy.deepcopy(x)
...: z
...:
...: x25]: [1, 2, 3]
Out[
26]:
In [
26]: z
In [26]: [1, 2, 3]
Out[
27]: x.append(4)
In [
28]: x
In [28]: [1, 2, 3, 4]
Out[
29]: z
In [29]: [1, 2, 3]
Out[
31]: z.append(5)
In [
# NOTE : x, z NOT affect on each other
32]: z
In [32]: [1, 2, 3, 5]
Out[
33]: x
In [33]: [1, 2, 3, 4] Out[
8]: def test(l1, l2):
In [if l1 or l2:
...: return l1 or l2
...:
...:= test("l1", None)
...: res print (res)
...:
...:= test(None, "l2")
...: res2 print (res2)
...:
l1 l2
if len(l1) < len(l2):
= l2, l1 l1, l2
# LC 008
= '4193 with words'
s = re.search('(^[\+\-]?\d+)', s).group()
res print (res)
# https://github.com/yennanliu/CS_basics/blob/master/doc/cheatsheet/math.md
# How does int(x[,base]) work?
# -> https://stackoverflow.com/questions/33664451/how-does-intx-base-work
# -> int(string, base) accepts an arbitrary base. You are probably familiar with binary and hexadecimal, and perhaps octal; these are just ways of noting an integer number in different bases:
# exmaple :
# In [76]: int('10',2) # transform '10' from 2 based to 10 based
# Out[76]: 2
#
# In [77]: int('11',2) # # transform '11' from 2 based to 10 based
# Out[77]: 3
#
# In [78]: int('100',2) # # transform '100' from 2 based to 10 based
# Out[78]: 4
# LC 089
# LC 451 Sort Characters By Frequency
# V1
import collections
class Solution(object):
def frequencySort(self, s):
= collections.Counter(s)
d = dict(d)
d_dict = []
res for x in sorted(d_dict, key=lambda k : -d_dict[k]):
res.append(x)return res
= [1, 2, 3, 1, 2, 1, 2, 1]
x= Solution()
s = s.frequencySort(x)
r
# V2
# https://stackoverflow.com/questions/613183/how-do-i-sort-a-dictionary-by-value
import collections
class Solution(object):
def frequencySort(self, s):
= collections.Counter(s)
d = dict(d)
d_dict = []
res #for x in sorted(d_dict.items(), key=lambda items: -items[1]):
for _ in sorted(d_dict.items(), key=lambda x: -x[1]):
res.append(_)return res
= [1, 2, 3, 1, 2, 1, 2, 1]
x= Solution()
s = s.frequencySort(x) r
# syntax :
# arr.insert(<index>,<value>)
12]: x = [1,2,3]
In [2,77)
...: x.insert(
13]: x
In [13]: [1, 2, 77, 3] Out[
1]: x = [1,2,3]
In [
2]: x
In [2]: [1, 2, 3]
Out[
3]: x.insert(0,0)
In [
4]: x
In [4]: [0, 1, 2, 3]
Out[
5]: x.insert(0,-1)
In [
6]: x
In [6]: [-1, 0, 1, 2, 3] Out[
def _sort(x):
= list(x)
_x
_x.sort()return "".join(_x)
= "bca"
x print (x)
= _sort(x)
x_ print (x_)
1]: x,y = divmod(100, 3)
In [
2]: x
In [2]: 33
Out[
3]: y
In [3]: 1 Out[
# example 1
36]: a = "000"
In [
37]: all( i == "0" for i in a )
In [37]: True
Out[
# example 2
38]: b = "abc123"
In [
39]: all ( i == "a" for i in b )
In [39]: False
Out[
# LC 763. Partition Labels
class Solution(object):
def partitionLabels(self, s):
= {val:idx for idx, val in enumerate(list(s))}
d #print (d)
= []
res = set()
tmp for idx, val in enumerate(s):
"""
NOTE : below condition
"""
if idx == d[val] and all(idx >= d[t] for t in tmp):
+1)
res.append(idxelse:
tmp.add(val)= [res[0]] + [ res[i] - res[i-1] for i in range(1, len(res)) ]
_res return _res
not
logic#----------------------------
# can be either None, [], ""
#----------------------------
32]: x = None
In [
34]: not x
In [34]: True
Out[
35]: y = []
In [
36]: not y
In [36]: True
Out[
37]: z = ""
In [
38]: not z
In [38]: True Out[
sort
on a
lambda func
# example 1
# LC 973. K Closest Points to Origin
# IDEA : sort + lambda
class Solution(object):
def kClosest(self, points, K):
= lambda x : x[0]**2 + x[1]**2)
points.sort(key return points[:K]
# example 2
28]: def my_func(x):
In [return x**2
...:
...:= [-4,-5,0,1,2,5]
...: x =lambda x: my_func(x))
...: x.sort(keyprint (x)
...: 0, 1, 2, -4, -5, 5] [
# LC 937
# https://leetcode.com/problems/reorder-data-in-log-files/solution/
def my_func(input):
# do sth
if condition:
return key1, key2, key3....
else:
return key4, key5, key6....
=["a1 9 2 3 1","g1 act car","zo4 4 7","ab1 off key dog","a8 act zoo"]
my_array=lambda x : my_func) my_array.sort(key
#-----------------
# V1 : %=
#-----------------
7]: x = 100
In [
8]: x %= 60
In [
9]: x
In [9]: 40
Out[
10]: y = 120
In [
11]: y %= 60
In [
12]: y
In [12]: 0
Out[
#-----------------
# V2 : divmod
#-----------------
13]: a = 100
In [
14]: q, r = divmod(a, 60)
In [
15]: q
In [15]: 1
Out[
16]: r
In [16]: 40
Out[
17]: b = 120
In [
18]: q2, r2 = divmod(b, 60)
In [
19]: q2
In [19]: 2
Out[
20]: r2
In [20]: 0 Out[
# LC 1010
# V0
# IDEA : dict
class Solution(object):
def numPairsDivisibleBy60(self, time):
= {}
rem = 0
pairs for t in time:
#print ("rem = " + str(rem))
%= 60
t if (60 - t) % 60 in rem:
+= rem[(60 - t) % 60]
pairs if t not in rem:
= 1
rem[t] else:
+= 1
rem[t] return pairs
split
method# python
# syntax : split(separator, number_of_split_result)
# example 1
# In [17]: x = 'dig1 8 1 5 1'
# In [18]: x
# Out[18]: 'dig1 8 1 5 1'
# In [19]: x.split(" ")
# Out[19]: ['dig1', '8', '1', '5', '1']
# In [20]: x.split(" ", 1)
# Out[20]: ['dig1', '8 1 5 1']
# In [21]: x.split(" ", 2)
# Out[21]: ['dig1', '8', '1 5 1']
# In [22]: x.split(" ", 3)
# Out[22]: ['dig1', '8', '1', '5 1']
# In [23]: x.split(" ", 4)
# Out[23]: ['dig1', '8', '1', '5', '1']
# In [24]: x.split(" ", 100)
# Out[24]: ['dig1', '8', '1', '5', '1']
# example 2
# LC 937 Reorder Data in Log Files
class Solution:
def reorderLogFiles(self, logs):
def f(log):
= log.split(" ", 1)
id_, rest return (0, rest, id_) if rest[0].isalpha() else (1,)
= lambda x : f(x))
logs.sort(key return logs #sorted(logs, key = f)
extend
# LC 969. Pancake Sorting
10]: x = [1,2,3]
In [
11]: x.extend([4])
In [
12]: x
In [12]: [1, 2, 3, 4]
Out[
13]: x = [1,2,3]
In [
14]: x = x + [4]
In [
15]: x
In [15]: [1, 2, 3, 4] Out[
ceil
# https://www.runoob.com/python/func-number-ceil.html
# https://www.runoob.com/python/func-number-ceil.html
"""
The method ceil(x) in Python returns a ceiling value of x
-> i.e., the SMALLEST integer GREATER than or EQUAL to x.
"""
9]:
In [import math
...:
...:# prints the ceil using ceil() method
...: print ("math.ceil(-23.11) : ", math.ceil(-23.11))
...: print ("math.ceil(300.16) : ", math.ceil(300.16))
...: print ("math.ceil(300.72) : ", math.ceil(300.72))
...: -23.11) : -23
math.ceil(300.16) : 301
math.ceil(300.72) : 301
math.ceil(
# LC 875. Koko Eating Bananas
#...
# Iterate over the piles and calculate hour_spent.
# We increase the hour_spent by ceil(pile / middle)
for pile in piles:
# python ceil : https://www.runoob.com/python/func-number-ceil.html
+= math.ceil(pile / middle)
hour_spent # Check if middle is a workable speed, and cut the search space by half.
if hour_spent <= h:
= middle
right else:
= middle + 1
left #...
floor
# https://www.geeksforgeeks.org/floor-ceil-function-python/
"""
floor() method in Python returns the floor of x
-> i.e., the LARGEST integer NOT GREATER than x.
"""
# This will import math module
import math
8]: import math
In [
...:# prints the ceil using floor() method
...: print ("math.floor(-23.11) : ", math.floor(-23.11))
...: print ("math.floor(300.16) : ", math.floor(300.16))
...: print ("math.floor(300.72) : ", math.floor(300.72))
...: -23.11) : -24
math.floor(300.16) : 300
math.floor(300.72) : 300 math.floor(
= {'a':1, 'b':2, 'c': 3}
d # loop over key, value
for k, v in d.items():
print (k, v)
# loop over key
for k in d.keys():
print (k)
# loop over value
for v in d.values():
print (v)
zip()
# python
1]: for x, y in zip([-1, 1, 0, 0], [0, 0, -1, 1]):
In [print (x, y)
...:
...:-1 0
1 0
0 -1
0 1
2]: for x, y, z in zip([-1, 1, 0, 0], [0, 0, -1, 1], [0,0,0,0]):
In [print (x,y,z)
...:
...:-1 0 0
1 0 0
0 -1 0
0 1 0
3]: for x, y, z, u in zip([-1, 1, 0, 0], [0, 0, -1, 1], [0,0,0,0], [9,9,9,9]):
In [print (x,y,z,u)
...:
...:-1 0 0 9
1 0 0 9
0 -1 0 9
0 1 0 9
eval()
# https://www.runoob.com/python/python-func-eval.html
# https://www.programiz.com/python-programming/methods/built-in/eval
# The eval() method parses the expression passed to this method and runs python expression (code) within the program.
# LC 640
# LC 150
# syntax : eval(expression[, globals[, locals]])
# eample
51]: x = 7
In [eval('3 * x')
...:
...:51]: 21
Out[
52]: eval ('2 + 2')
In [
...:52]: 4
Out[
53]: n = 81
In [eval('n + 4')
...: 53]: 85 Out[
*
”)
expression# Extended Iterable Unpacking
# https://www.python.org/dev/peps/pep-3132/
# http://swaywang.blogspot.com/2012/01/pythonstarred-expression.html
# example 1
38]: a, *b, c = range(5)
In [
39]: a
In [39]: 0
Out[
40]: b
In [40]: [1, 2, 3]
Out[
41]: c
In [41]: 4
Out[
# example 2
43]: for a, *b in [(1, 2, 3), (4, 5, 6, 7)]:
In [print ("a = " + str(a) + " b = " + str(b))
...:
...:= 1 b = [2, 3]
a = 4 b = [5, 6, 7]
a
# example 3
44]: first, *rest = [1, 2, 3, 4, 5]
In [
45]: first
In [45]: 1
Out[
46]: rest
In [46]: [2, 3, 4, 5]
Out[
# example 4
47]: *directories, executable = "/usr/local/bin/vim".split("/")
In [print (directories)
...: print (executable)
...: '', 'usr', 'local', 'bin']
[
vim
# example 5
= [1,3]
args print (range(*args))
datetime() <-> string()
# LC 681.Next Closest Time
# https://github.com/yennanliu/CS_basics/blob/master/leetcode_python/String/next-closest-time.py
from datetime import datetime, timedelta
= "10:20"
x
#--------------------------------------
# strptime : string -> datetime
# (Return a datetime corresponding to date_string, parsed according to format.)
#--------------------------------------
= datetime.strptime(x, "%H:%M")
x_datetime print (x_datetime)
# 1900-01-01 10:20:00
#--------------------------------------
# strftime : datetime -> string
# (Return a string representing the date)
#--------------------------------------
= x_datetime.strftime("%H:%M")
x_str print (x_str)
# 10:20
# eatra : timedelta
= x_datetime + timedelta(minutes=10)
tmp print (tmp)
# 1900-01-01 10:30:00
itertools
# https://docs.python.org/zh-cn/3/library/itertools.html
# https://docs.python.org/zh-tw/3/library/itertools.html
# itertools — Functions creating iterators for efficient looping
#-----------------------------------------------------------------------------------------------------
# example 1 : itertools.accumulate : Aggregated sum
#-----------------------------------------------------------------------------------------------------
10]: import itertools
In [= itertools.accumulate(range(10))
...: x print (list(x))
...: 0, 1, 3, 6, 10, 15, 21, 28, 36, 45]
[
#-----------------------------------------------------------------------------------------------------
# example 2 : itertools.combinations : get NON-duplicated elements from collections (with given len)
#-----------------------------------------------------------------------------------------------------
15]: x = itertools.combinations(range(4), 3)
In [
16]: print (list(x))
In [0, 1, 2), (0, 1, 3), (0, 2, 3), (1, 2, 3)]
[(
17]: x = itertools.combinations(range(4), 4)
In [
18]: print (list(x))
In [0, 1, 2, 3)]
[(
#-----------------------------------------------------------------------------------------------------
# example 3 : itertools.combinations_with_replacement : get duplicated or non-duplicated elements from collections (with given len)
#-----------------------------------------------------------------------------------------------------
19]: x = itertools.combinations_with_replacement('ABC', 2)
In [
20]: print(list(x))
In ['A', 'A'), ('A', 'B'), ('A', 'C'), ('B', 'B'), ('B', 'C'), ('C', 'C')]
[(
21]: x = itertools.combinations_with_replacement('ABC', 1)
In [
22]: print(list(x))
In ['A',), ('B',), ('C',)]
[(
24]: x = itertools.combinations_with_replacement([1,2,2,1], 2)
In [
25]: print (list(x))
In [1, 1), (1, 2), (1, 2), (1, 1), (2, 2), (2, 2), (2, 1), (2, 2), (2, 1), (1, 1)]
[(
#-----------------------------------------------------------------------------------------------------
# example 4 : itertools.compress : filter elements by True/False
#-----------------------------------------------------------------------------------------------------
26]: x = itertools.compress(range(5), (True, False, True, True, False))
In [
27]: print (list(x))
In [0, 2, 3]
[
#-----------------------------------------------------------------------------------------------------
# example 5 : itertools.count : a counter, can define start point and path len
#-----------------------------------------------------------------------------------------------------
# NOTE THIS !!!!
2]: x = itertools.count(start=20, step=-1)
In [
3]: print(list(itertools.islice(x, 0, 10, 1)))
In [20, 19, 18, 17, 16, 15, 14, 13, 12, 11]
[
#-----------------------------------------------------------------------------------------------------
# example 6 : itertools.groupby : group by lists by value
#-----------------------------------------------------------------------------------------------------
4]: x = itertools.groupby(range(10), lambda x: x < 5 or x > 8)
In [
5]: for condition, numbers in x:
In [print(condition, list(numbers))
...:
...:True [0, 1, 2, 3, 4]
False [5, 6, 7, 8]
True [9]
#-----------------------------------------------------------------------------------------------------
# example 7 : itertools.islice : slice on iterator
#-----------------------------------------------------------------------------------------------------
# https://docs.python.org/3/library/itertools.html#itertools.islice
# syntax : itertools.islice(seq, [start,] stop [, step])
6]: x = itertools.islice(range(10), 0, 9, 2)
In [
7]: print (list(x))
In [0, 2, 4, 6, 8]
[
#-----------------------------------------------------------------------------------------------------
# example 8 : itertools.permutations : generate all combinations (ordering mattered)
#-----------------------------------------------------------------------------------------------------
9]: x = itertools.permutations(range(4), 3)
In [
10]: print(list(x))
In [0, 1, 2), (0, 1, 3), (0, 2, 1), (0, 2, 3), (0, 3, 1), (0, 3, 2), (1, 0, 2), (1, 0, 3), (1, 2, 0), (1, 2, 3), (1, 3, 0), (1, 3, 2), (2, 0, 1), (2, 0, 3), (2, 1, 0), (2, 1, 3), (2, 3, 0), (2, 3, 1), (3, 0, 1), (3, 0, 2), (3, 1, 0), (3, 1, 2), (3, 2, 0), (3, 2, 1)]
[(
#-----------------------------------------------------------------------------------------------------
# example 9 : itertools.product : generate multiple lists, and iterators's product
#-----------------------------------------------------------------------------------------------------
11]: x = itertools.product('ABC', range(3))
In [
12]: print(list(x))
In ['A', 0), ('A', 1), ('A', 2), ('B', 0), ('B', 1), ('B', 2), ('C', 0), ('C', 1), ('C', 2)] [(
remove
,
append
# LC 146 LRU Cache
18]: x
In [18]: [1, 3, 2]
Out[
19]: x = [1,2,3]
In [
# NOTE this !!!!
# LC 146
20]: x.remove(2)
In [#x
#[1,2]
21]: x.append(2)
In [
22]: x
In [22]: [1, 3, 2]
Out[
23]:
In [
23]: x.remove(1)
In [
24]: x.append(1)
In [
25]: x
In [25]: [3, 2, 1] Out[
OrderedDict
( hashmap + linked list)filter()
# https://www.runoob.com/python/python-func-filter.html
#-----------------------------------------------
# syntax : filter(<filter_func>, <iterable>)
#-----------------------------------------------
# note !!! : in py 3, it will return iterable instance; while in py 2, it will return a list directly
#----------------------------
# example 1
#----------------------------
13]: def is_odd(n):
In [return n % 2 == 1
...:
...:= filter(is_odd, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
...: newlist print(newlist)
...: <filter object at 0x7fc71c3dced0>
14]:
In [
14]: list(newlist)
In [14]: [1, 3, 5, 7, 9]
Out[
#----------------------------
# example 2
#----------------------------
15]: import math
In [def is_sqr(x):
...: return math.sqrt(x) % 1 == 0
...:
...:= filter(is_sqr, range(1, 101))
...: newlist print(newlist)
...: <filter object at 0x7fc71bb10450>
16]:
In [
16]: list(newlist)
In [16]: [1, 4, 9, 16, 25, 36, 49, 64, 81, 100] Out[
#----------------------------
# example 1
#----------------------------
# https://stackoverflow.com/questions/4260280/if-else-in-a-list-comprehension
8]: [ x for x in range(5) ]
In [8]: [0, 1, 2, 3, 4]
Out[
# NOTE this !!!!
9]: [ x if x % 2 == 0 else -1 for x in range(5) ]
In [
...:
...:9]: [0, -1, 2, -1, 4]
Out[
10]: def my_func(x):
In [if x % 2 ==0:
...: return True
...: return False
...:
...:if my_func(x) else 999 for x in range(5)]
...: [ x 10]: [0, 999, 2, 999, 4] Out[
# 445 Add Two Numbers II
# 394 Decode String
def str_2_int(x):
=0
rfor i in x:
= int(r)*10 + int(i)
r print (i, r)
return r
def str_2_int_v2(x):
= 0
res for i in x:
= (res + int(i) % 10) * 10
res return int(res / 10)
# example 1
="131"
x=str_2_int(x)
rprint (r)
# 1 1
# 3 13
# 1 131
# 131
# examle 2
62]: z
In [62]: '5634'
Out[
63]: ans = 0
In [
64]: for i in z:
In [= 10 * ans + int(i)
...: ans
...:
65]: ans
In [65]: 5634 Out[
NOT sorting an array eveytime
whenever
there is a new inserted element# https://docs.python.org/zh-tw/3/library/bisect.html
# src code : https://github.com/python/cpython/blob/3.10/Lib/bisect.py
# https://myapollo.com.tw/zh-tw/python-bisect/
# https://www.liujiangblog.com/course/python/57
"""
NOTE !!! before using bisect, we need SORT the array
"""
#-------------------------------
# bisect_left
#-------------------------------
# will return an idx for inserting new element a, and keep the new array sorted, if element a already existed in array, will insert to "original" a's left idx
# example 1
3]: import bisect
In [= [2,4,6]
...: a = bisect.bisect_left(a, 3)
...: idx print (idx)
...:
...:3)
...: a.insert(idx, print (a)
...:
...:1
2, 3, 4, 6]
[
# example 2
4]: import bisect
In [= [2, 4, 6]
...: a = bisect.bisect_left(a, 4)
...: idx print (idx)
...:
...:4)
...: a.insert(idx, print (a)
...: 1
2, 4, 4, 6]
[
#-------------------------------
# bisect_right
#-------------------------------
# will return an idx for inserting new element a, and keep the new array sorted, if element a already existed in array, will insert to "original" a's right idx
5]:
In [import bisect
...: = a = [2, 2, 4, 4, 6, 6, 8, 8]
...: a = bisect.bisect_right(a, 4)
...: idx print (idx)
...:
...:4)
...: a.insert(idx, print (a)
...: 4
2, 2, 4, 4, 4, 6, 6, 8, 8]
[
#-------------------------------
# bisect
#-------------------------------
# bisect.bisect :
# -> similar as bisect.bisect_right
# -> similar as bisect.bisect_left, but will insert to element RIGHT instead
# https://docs.python.org/zh-tw/3/library/bisect.html
# https://blog.csdn.net/qq_34914551/article/details/100062973
# example 1
# In [3]: import bisect
# ...: a = [2, 4, 6, 8]
# ...: idx = bisect.bisect(a, 7)
# ...: print (idx)
# ...: a.insert(idx, 7)
# ...: print (a)
# 3
# [2, 4, 6, 7, 8]
#-------------------------------
# insort, insort_right, insort_left
#-------------------------------
# insort, insort_right, insort_left : will get idx and insert to array (with idx) directly
# example 1
8]: import bisect
In [= [2, 4, 6, 8]
...: a 4)
...: bisect.insort_left(a, print (a)
...:
...:2, 4, 4, 6, 8]
[
# exmaple 2
7]: import bisect
In [= [2, 4, 6, 8]
...: a 4)
...: bisect.insort_right(a, print (a)
...: 2, 4, 4, 6, 8] [
functools
modules@lru_cache(maxsize=32) def get_pep(num): ‘Retrieve text of a Python Enhancement Proposal’ resource = ‘https://www.python.org/dev/peps/pep-%04d/’ % num try: with urllib.request.urlopen(resource) as s: return s.read() except urllib.error.HTTPError: return ‘Not Found’
@lru_cache(maxsize=None) def fib(n): if n < 2: return n return fib(n-1) + fib(n-2)
@api.route(“/user/info”, methods=[“GET”]) @functools.lru_cache() @login_require def get_userinfo_list(): userinfos = UserInfo.query.all() userinfo_list = [user.to_dict() for user in userinfos] return jsonify(userinfo_list)
### 1-29) fill "0" to String
```python
# LC 67. Add Binary
#NOTE : zfill syntax
# -> fill n-1 "0" to a string at beginning
#example :
In [10]: x = '1'
In [11]: x.zfill(2)
Out[11]: '01'
In [12]: x.zfill(3)
Out[12]: '001'
In [13]: x.zfill(4)
Out[13]: '0001'
In [14]: x.zfill(10)
Out[14]: '0000000001'