Skip to content

Instantly share code, notes, and snippets.

for s in iter(input, "0"):
print(s)
# Input
# 123
# 55
# 1000
# 0
# Output
# buildings[4][3][10]
buildings = [[[0 for i in range(10)] for j in range(3)] for k in range(4)]
a = 123.456789
b = round(a, 3)
print(b)
# => 123.457
a = divmod(10, 3)
print(a)
# => (3, 1)
l = ['a', 'b', 'c']
for i, c in enumerate(l, start=1):
print(i, c)
@peroon
peroon / intでの割り算.py
Last active March 29, 2017 08:51
floating point division, integer division
print(100 / 3) # 33.333333
print(100 // 3) # 33
a = 5
b = a / 2
print(b) #=> 2.5
c = a >> 1
print(c) #=> 2
def call():
print('call')
for i in range(0, N):
for j in range(i+1, N):
call()
# Q. callは何回呼ばれるか?
# A. N-1, N-2, ..., 1の和なので、(N-1) * N / 2
def test():
A = [5,2,4,6,1,3]
print(A)
for i in range(1, len(A)):
print('A', A)
v = A[i]
# search insert position
j = i - 1
A = set([1,2,3])
B = set([2,3,4])
A ^ B
=> set([1, 4])