ํ์ด์ฌ
1๏ธโฃ ๋ฆฌ์คํธ์ ํ๊ณผ ์ด์ ๋ณํํ๋ ๋ฐฉ๋ฒ 1
new_board = [list(i) for i in zip(*board)]
2๏ธโฃ ๋ฆฌ์คํธ์ ํ๊ณผ ์ด์ ๋ณํํ๋ ๋ฐฉ๋ฒ 2
new_board = list(map(list, zip(*board)))
โ ์์
board = [[1, 2, 3],
[4, 5, 6],
[7, 8, 9]]
new_board = [list(i) for i in zip(*board)]
for i in new_board:
print(i)
์ถ๋ ฅ ๊ฒฐ๊ณผ
[1, 4, 7]
[2, 5, 8]
[3, 6, 9]
zip()
ํ์ด์ฌ์ zip() ํจ์๋ ์ฌ๋ฌ ์ดํฐ๋ฌ๋ธ(iterable)(๋ฆฌ์คํธ, ํํ ๋ฑ)์ ๋์์ ์ํํ๋ฉด์, ๊ฐ ์ดํฐ๋ฌ๋ธ์ ๋์ผํ ์ธ๋ฑ์ค์ ์๋ ์์๋ค์ ํํ๋ก ๋ฌถ์ด ๋ฐํํ๋ ํจ์์ด๋ค. ์ฆ, ์ฌ๋ฌ ์ํ์ค์ ์์๋ค์ ํ๋์ฉ ์ฐจ๋ก๋๋ก ์ง์ง์ด์ค๋ค.
๊ธฐ๋ณธ ๊ตฌ๋ฌธ
zip(iterable1, iterable2, ...)
- ์ ๋ ฅ : ์ฌ๋ฌ ๊ฐ์ ์ดํฐ๋ฌ๋ธ ๊ฐ์ฒด (์: ๋ฆฌ์คํธ, ํํ ๋ฑ).
- ์ถ๋ ฅ : ๊ฐ ์ดํฐ๋ฌ๋ธ์ ์์๋ค์ ๋ฌถ์ ํํ๋ก ์ด๋ฃจ์ด์ง ์ดํฐ๋ ์ดํฐ.
โ ์์
a = [1, 2, 3]
b = [4, 5, 6]
for i, j in zip(a, b):
print(i + j)
์ถ๋ ฅ ๊ฒฐ๊ณผ
5
7
9
- a ๋ฆฌ์คํธ์ b ๋ฆฌ์คํธ๋ฅผ ๋ฌถ์ด์ ์์๋ฅผ ๊ฐ์ด ๊บผ๋ผ ์ ์๋ค.
- a ๋ฆฌ์คํธ๋ i, b ๋ฆฌ์คํธ๋ j๋ก ๊บผ๋ด์ ธ์ a ๋ฆฌ์คํธ์ ์์์ b ๋ฆฌ์คํธ์ ์์๊ฐ ๊ฐ๊ฐ ๋ํด์ง ๊ฒฐ๊ณผ๋ฅผ ๋ณผ ์ ์๋ค.
Markdown
์ค ๋ฐ๊ฟ
<br>
์ฝ๋์ ๊ฐ๋ ์ฑ ๋์ด๊ธฐ
๊ฐ ์น์ ์ ๋ํด ๋ช ํํ ์ฃผ์์ ๋ฌ๋ฉด ๊ฐ๋ ์ฑ์ ๋์ผ ์ ์๋ค.
๐ ์์ฑํ ๊ฒ์๊ธ
[SWEA ์ฝ๋ฉํ ์คํธ 1216] ๐ https://dev-cloud.tistory.com/338
[SWEA ์ฝ๋ฉํ ์คํธ 14692] ๐ https://dev-cloud.tistory.com/339
[SWEA ์ฝ๋ฉํ ์คํธ 1209] ๐ https://dev-cloud.tistory.com/340
[Programmers ์ฝ๋ฉํ ์คํธ L1. ์์ ๋ํ๊ธฐ] ๐ https://dev-cloud.tistory.com/341
[Programmers ์ฝ๋ฉํ ์คํธ L1. ๋ด์ ] ๐ https://dev-cloud.tistory.com/342
[Programmers ์ฝ๋ฉํ ์คํธ L1. ๋ถ์กฑํ ๊ธ์ก ๊ณ์ฐํ๊ธฐ] ๐ https://dev-cloud.tistory.com/343
[ํ์ด์ฌ ๋์ ๋๋ฆฌ ์ ๋ฆฌ] ๐ https://dev-cloud.tistory.com/344
[ํ์ด์ฌ zip() ํจ์ ์ ๋ฆฌ] ๐ https://dev-cloud.tistory.com/345
[Programmers ์ฝ๋ฉํ ์คํธ L1. ํฌ๊ธฐ๊ฐ ์์ ๋ถ๋ถ๋ฌธ์์ด] ๐ https://dev-cloud.tistory.com/347
'๐ Growth > TIL' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
| [TIL] 2024๋ 10์ 29์ผ (0) | 2024.10.29 |
|---|---|
| [TIL] 2024๋ 10์ 26์ผ (0) | 2024.10.29 |
| [TIL] 2024๋ 10์ 24์ผ (0) | 2024.10.24 |
| [TIL] 2024๋ 10์ 22์ผ (0) | 2024.10.23 |
| [TIL] 2024๋ 10์ 21์ผ (0) | 2024.10.21 |