๋์ด์ฐ๊ธฐ ์๋ ์ซ์๋ฅผ ์ ๋ ฅ๋ฐ์์ ์ซ์ ๋ฆฌ์คํธ๋ก ๋ง๋ค๊ธฐ
map ๊ฐ์ฒด๋ ์ดํฐ๋ ์ดํฐ์์ ํ์ฉํ๋ค.
๊ทธ๋ฅ ์ซ์ 1101101 ์ ์ดํฐ๋ ์ดํฐ๊ฐ ์๋์ง๋ง, map ๊ฐ์ฒด๋ก ๋ํ๋ ์ซ์ 1101101 ์ ์ดํฐ๋ ์ดํฐ์ด๋ค.
๋ฐ๋ผ์ list(map(int, "1101101")) ๋ [1, 1, 0, 1, 1, 0, 1] ์ด ๋๋ค.
print(type("1101101")) # <class 'str'>
print(map(int, "1101101")) # <map object at 0x7fa1b0194e50>
for x in map(int, "1101101"):
print(type(x), x)
"""
<class 'int'> 1
<class 'int'> 1
<class 'int'> 0
<class 'int'> 1
<class 'int'> 1
<class 'int'> 0
<class 'int'> 1
"""
print(list(map(int, "1101101"))) # [1, 1, 0, 1, 1, 0, 1]
print(list("1101101")) # ['1', '1', '0', '1', '1', '0', '1']
print(list(1101101)) # TypeError: 'int' object is not iterable
# ์ด ๋ฐฉ๋ฒ๋ ๊ฐ๋ฅ. ์์ ์ฒ์๋ถํฐ "1101101"์ ๋ฌธ์์ด ๋ฆฌ์คํธ๋ก ์ชผ๊ฐ ๋ค.
print(list(map(int, list("1101101")))) # [1, 1, 0, 1, 1, 0, 1]
Python
๋ณต์ฌ