์ผ | ์ | ํ | ์ | ๋ชฉ | ๊ธ | ํ |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 | 29 |
30 | 31 |
- ๋๊ธฐ
- eport
- ํผํ
- prj
- js
- Project
- ๋น๋๊ธฐ
- slow and steady
- Import
- setTimeout()
- Porject
- db
- ajax
- JS #ํ๋ก์ ํธ
- ์ฐธ๊ณ ๋ธ๋ก๊ทธ
- async
- execCommand
- json
- callback
- addEventListener
- database
- https://m.blog.naver.com/tt2t2am1118/221010125300
- ๊ฒ์
- await
- sql
- https://youtube.com/playlist?list=PLuHgQVnccGMA5836CvWfieEQy0T0ov6Jh&si=FTaYv8m21EhO-A2K
- webpack
- promise
- object
- mysql
- Today
- Total
C-log
์ฌ์ฌํ์ด ๋ ์ฝฉ๐ฅ : ๊ธฐ๋ณธ ์ ๋ ฅ๊ณผ ์ถ๋ ฅ ๊ฐ ๋์ถ ํ๊ธฐ ๋ณธ๋ฌธ
์ฌ์ฌํ์ด ๋ ์ฝฉ๐ฅ : ๊ธฐ๋ณธ ์ ๋ ฅ๊ณผ ์ถ๋ ฅ ๊ฐ ๋์ถ ํ๊ธฐ
4:Bee 2024. 6. 17. 23:21์๊ณ ๋ฆฌ์ฆ์ ๊ณต๋ถํ ๋ ๊ธฐ๋ณธ์ ์ผ๋ก ํํํ๊ฒ ์์์ผ ํ๋ ๊ฒ์ด ๊ธฐ๋ณธ ์ ์ถ๋ ฅ ์ด๋ผ๊ณ ์๊ฐํ๋ค. ์ด ์๋ น์ด ์์ผ๋ฉด ์ด๋ค ๋ฌธ์ ๋ผ๋ ํด๊ฒฐํด๋ด๊ธฐ ์ด๋ ต๋ค๊ณ ์๊ฐํด์ ์ด๋ ๊ฒ ํฌ์คํ ์ ํ๊ฒ ๋์๋ค.
๊ธฐ๋ณธ์ ์ธ input() ์ ์ธ
- ์ผ๋ฐ์์ธ input ๋ฐฉ์
#--- input() ---
inputValue = input()
print(type(inputValue))
# test ์
๋ ฅ ์ -> str
# 123 ์
๋ ฅ ์ -> str
# ๊ฒฐ๋ก : ๋จ์ผ input์ ํ์ ์ ๊ธฐ๋ณธ str์ ๋ฐํํ๊ฒ ๋๋ค.
* ์๋ ์ฝ๋๋ค์ inputValue ๋ณ์์ ์ ์ธํ input()ํจ์๋ฅผ ํ์ฉํ ์ฌ๋ก์ด๋ค. input()ํจ์์ ์ง์ split()์ ์ ์ฉํ ์ ์์ง๋ง ํธ์๋ฅผ ์ํด input()๊ณผ split()์ ๋ฐ๋ก ๋ถ๋ฆฌ ํ์๋ค.
list() ํ๋ณํ ์์ด List๋ก ์ ์ธํ๋ ๋ฐฉ๋ฒ
inputList = [inputValue] #์
๋ ฅ ๊ฐ ๊ทธ๋๋ก ๋ฐฐ์ด์ ๋ฃ๋ ๋ฐฉ๋ฒ
print(inputList)
# Hello world -> list /['Hello word']
# test ์
๋ ฅ ์ -> list /['str']
# 123 ์
๋ ฅ ์ -> list /['str']
#๊ฒฐ๋ก :
Split์ ์ฌ์ฉํด์ 2์ค ๋ฐฐ์ด ์ ์ธ ํ๋ ๋ฐฉ๋ฒ
inputList = [inputValue.split()] #split์ผ๋ก ๊ตฌ๋ถ๋ ๊ฐ์ ๋ฐฐ์ด์ ๋ฃ๋ ๋ฐฉ๋ฒ ๋จ, ์ด์ค ๋ฐฐ์ด์ด ๋๋ค.
print(inputList)
# Hello world -> list /[['Hello', 'word']]
# test ์
๋ ฅ ์ -> list /[['test']]
# 123 ์
๋ ฅ ์ -> list /[['123']]
#๊ฒฐ๋ก : split์ list๋ก ๋ฐํ์ ํ๋ค ๋ฐ๋ผ์ inputValue.split()์ ๊ฐ์ด ์์ฑํ๋ฉด 1์ฐจ์ ๋ฐฐ์ด์ด ๋๋ค.
Split์ ์ฌ์ฉํด์ ๋ฐฐ์ด ์ ์ธํ๊ธฐ
inputList = inputValue.split()
print(inputList)
# Hello world -> list /['Hello', 'world']
# test ์
๋ ฅ ์ ->
# 123 ์
๋ ฅ ์ ->
#๊ฒฐ๋ก :
for๋ฌธ์ผ๋ก ๋ฌธ์์ด(str-list) ๋ถ๋ฆฌํ๊ธฐ
# -- inputList = [i for i in inputValue] --
inputList = [i for i in inputValue] #for๋ฌธ์ ์ฌ์ฉํด์ ์ซ์๋ง ๊ฐ๋ฅํ๊ฒ ํ์
์ ์ง์
print(inputList)
# Hello world -> str /['H', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'd']
# test ์
๋ ฅ ์ -> str /['t','e','s','t']
# 123 ์
๋ ฅ ์ -> str /['1','2','3']
#๊ฒฐ๋ก :
(ํ๋ณํโญ) Split์ผ๋ก ์ฒ๋ฆฌ ํ for๋ฌธ์ผ๋ก ๋ถ๋ฆฌ๋ ๊ฐ๋ค์ List๋ก ๊ฐ๊ณต ํ๋ ๋ฐฉ๋ฒ
# -- print(list(inputList)) --
inputList = (i for i in inputValue.split())
print(list(inputList)) # ์ ๋๋ ์ดํฐ๋ฅผ ๋ฆฌ์คํธ๋ก ๋ณํํ์ฌ ์ถ๋ ฅ
# Hello world ->
# test ์
๋ ฅ ์ ->
# 123 ์
๋ ฅ ์ ->
#๊ฒฐ๋ก : inputList = (i for i in inputValue.split())๋ก ์ฝ๋๋ฅผ ์์ฑ ํ์ list๋ก ๋ฌถ์ด์ผ for๋ฌธ์ผ๋ก ํด์ฒด๊ฐ ๋ ๊ฐ๋ค์ ๋ณด์ฌ ์ค ์ ์๋ค ๋ฐ๋ผ์ list()๋ก ํ๋ณํ์ ํ๋ ๊ณผ์ ์ด ํ์ํ๋ค.
(ํ๋ณํโ) Split์ผ๋ก ์ฒ๋ฆฌ ํ for๋ฌธ์ผ๋ก ๋ถ๋ฆฌ๋ ๊ฐ๋ค์ List๋ก ์ ์ธ ํ๋ ๋ฐฉ๋ฒ
# -- inputList = [i for i in inputValue.split()] --
inputList = [i for i in inputValue.split()] #for๋ฌธ์ ์ฌ์ฉํด์ split์ ํตํด์ 'inputValue.split()'๋ก ์ ์ฅ๋ ๋ฐฐ์ด์ for๋ฌธ์ผ๋ก ํด์ฒด๊ฐ ๋๋ค.
print(inputList)
# Hello world -> list /['Hello', 'word']
# test ์
๋ ฅ ์ -> list /['test']
# 123 ์
๋ ฅ ์ -> list /['123']
#๊ฒฐ๋ก :
ํญ์ ์ ์ธ์ ํ ๋ ๋ฐํ๋๋ ๊ฐ์ ํ์ ์ ํ์ธํด์ผ ํ๋ค ๊ทธ๋ ์ผ ๋ค์ ์ํ ๋์๊ณผ ๊ตฌํ ๋ฐฉ๋ฒ์ด ๋ฌ๋ผ์ง๊ธฐ ๋๋ฌธ์ด๋ค. ๋ฌผ๋ก ์ด๋์ ๋ ์ต์ํด์ง๊ณ ์๋ จ์ด ๋๋ฉด ํ์ธํ ํ์ ์์ด ๊ณ์ฐ์ ํ๊ฒ ์ง๋ง ์์ง์ ๋ถ์กฑํ๋ type()๋ก ํ์ธํ๋ฉฐ ์ฝ๋๋ฅผ ์์ฑํด ๋๊ฐ๋ฉด ์ข๋ค๊ณ ๋ณธ๋ค. ๋ซ๋ถํ์ ๋ณ์๋ช ๋ ์ด๋ป๊ฒ ์ ํ ์ง ๋๋ง์ ๋ณ์๋ช ๊ท์น์ด๋ ํต์์ ์ธ ๋ฐฉ๋ฒ์ด ๋ฌด์์ธ์ง๋ ๋ถ์ํด๊ฐ๋ฉด ์ข๊ฒ ๋ค.
'๐ง Algorithm > ์ฌ์ฌํ์ด ๋ ์ฝฉ๐ฅ' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
์ฌ์ฌํ์ด ๋ ์ฝฉ๐ฅ : ๊ธฐ๋ณธ for๋ฌธ ๋์ถ ํ๊ธฐ (0) | 2024.06.24 |
---|---|
์ฌ์ฌํ์ด ๋ ์ฝฉ๐ฅ : ์คํ(Stack) (0) | 2023.12.19 |
์ฌ์ฌํ์ด ๋ ์ฝฉ๐ฅ : ํ(Queue) (0) | 2023.12.02 |
์ฌ์ฌํ์ด ๋ ์ฝฉ๐ฅ : ํต ์ ๋ ฌ(Quick Sort) (0) | 2023.09.26 |
์ฌ์ฌํ์ด ๋ ์ฝฉ๐ฅ : ์ฝ์ ์ ๋ ฌ(Insertion Sort) (0) | 2023.09.19 |