# 풀이 1
>>> str(list(range(1, 10001))).count('8')
4000
# 풀이 2
>>> count = 0
... for i in range(10001):
... if '8' in str(i):
... count += str(i).count('8')
>>> count
4000
# 풀이 3
>>> str([i for i in range(10001)]).count('8')
4000
Tip! 속도 측정
%%timeit
- 코드를 여러번 실행하고 평균 시간을 측정해서 알려줌
# 풀이 1
>>> s = [1, 3, 4, 8, 13, 17, 20]
>>> m = max(s)
>>> m
20
>>> index = 0
>>> for i in range(len(s) - 1):
... if m > s[i+1] - s[i]:
... index = i
... m = s[i+1] - s[i]
>>> s[index], s[index+1]
(3, 4)
# 풀이 2
>>> s = [1, 3, 4, 8, 13, 17, 20]
>>> ss = [3, 4, 8, 13, 17, 20]
>>> list(zip(s, ss))
[(1, 3), (3, 4), (4, 8), (8, 13), (13, 17), (17, 20)]
>>> sorted(list(zip(s, ss)), key=lambda i: i[1])
[(1, 3), (3, 4), (4, 8), (8, 13), (13, 17), (17, 20)]
>>> sorted(list(zip(s, ss)), key=lambda i: i[1]-i[0])
[(3, 4), (1, 3), (17, 20), (4, 8), (13, 17), (8, 13)]
>>> sorted(list(zip(s, ss)), key=lambda i: i[1]-i[0])[0]
(3, 4)
# 풀이 3
>>> def 두수의차(i):
... return i[1] - i[0]
>>> sorted(list(zip(s, ss)), key=두수의차)
[(3, 4), (1, 3), (17, 20), (4, 8), (13, 17), (8, 13)]
>>> sorted(list(zip(s, ss)), key=두수의차)[0]
(3, 4)
# 풀이 1
>>> bin(9)
'0b1001'
>>> bin(30)
'0b11110'
>>> # 1001
>>> # 11110
>>> # -----
>>> # 11111
>>> bin(9 | 30)
'0b11111'
>>> bin(9 | 30)[:2]
'11111'
>>> bin(9 | 30)[:2].replace('1', '#').replace('0', ' ')
'#####'
>>> arr1 = [ 9, 20, 28, 18, 11]
>>> arr2 = [30, 1, 21, 17, 28]
>>> n = 5
>>> for i in zip(arr1, arr2):
... print(i)
(9, 30)
(20, 1)
(28, 21)
(18, 17)
(11, 28)
>>> for i, j in zip(arr1, arr2):
... print(i, j)
9 30
20 1
28 21
18 17
11 28
>>> for i, j in zip(arr1, arr2):
... print(bin(i | j)[2:].replace('1', '#').replace('0', ' '))
#####
# # #
### #
# ##
#####
>>> arr1 = [3, 20, 28, 18, 11]
>>> arr2 = [5, 1, 21, 17, 28]
>>> n = 5
>>> # 11
>>> # 101
>>> # ---
>>> # 111
>>> for i, j in zip(arr1, arr2):
... print(bin(i | j)[2:].replace('1', '#').replace('0', ' '))
###
# # #
### #
# ##
#####
>>> for i, j in zip(arr1, arr2):
... print(bin(i | j)[2:].zfill(n))
00111
10101
11101
10011
11111
>>> for i, j in zip(arr1, arr2):
... print(bin(i | j)[2:].zfill(10))
0000000111
0000010101
0000011101
0000010011
0000011111
>>> for i, j in zip(arr1, arr2):
... print(bin(i | j)[2:].zfill(n)).replace('1', '#').replace('0', ' '))
###
# # #
### #
# ##
#####
>>> def solution(n, arr1, arr2):
... answer = []
... for i, j in zip(arr1, arr2):
... anser.append(bin(i | j)[2:].zfill(n)).replace('1', '#').replace('0', ' '))
... return answer
# 풀이 1