728x90
๋ฐ˜์‘ํ˜•

Python 3

[python] ํ…์ŠคํŠธ ํŒŒ์ผ ์ž๋ฅด๊ธฐ (text file crop)

#ํŒŒ์ด์ฌ ํ…์ŠคํŠธ ํŒŒ์ผ ๋‚ ๋ฆฌ๊ธฐ #python textfile crop #python textfile delete line ๋‹ค์Œ๊ณผ ๊ฐ™์€ ํ…์ŠคํŠธํŒŒ์ผ์ด ์žˆ๋‹ค๊ณ  ํ•˜์ž ์—ฌ๊ธฐ์„œ ํŠน์ • line ํ˜น์€ ์—ฌ๋Ÿฌ๊ฐœ์˜ line์„ ์ง€์šฐ๊ณ  ์‹ถ๋‹ค๋ฉด..?? ์ ˆ๋ฐ˜์„ ๋‚ ๋ ค๋ฒ„๋ฆฌ๊ณ  ์‹ถ๋‹ค๋ฉด?? line 1 of the text file line 2 of the text file line 3 of the text file line 4 of the text file line 5 of the text file # 1. ํ…์ŠคํŠธ ํŒŒ์ผ ์ฝ์–ด๋“ค์ด๊ธฐ # filename์— ํ…์ŠคํŠธํŒŒ์ผ ๊ฒฝ๋กœ๋ฅผ string์œผ๋กœ ๋„ฃ์–ด์ค€๋‹ค filename = './textfile.txt' text_file = opend(filename).readlines() # 2. ์ง€์šฐ๊ณ  ์‹ถ์€ li..

[python list] ํŒŒ์ด์ฌ ๋ฆฌ์ŠคํŠธ ์•ˆ ๋ฆฌ์ŠคํŠธ ํŽผ์น˜๊ธฐ_how to flatten a list of lists in python

#ํŒŒ์ด์ฌ ๋ฆฌ์ŠคํŠธ ํŽผ์น˜๊ธฐ #ํŒŒ์ด์ฌ 2d ๋ฆฌ์ŠคํŠธ ํŽผ์น˜๊ธฐ #python 2d list flatten #python nested list flatten ๋‹ค์Œ๊ณผ ๊ฐ™์ด 2D list๋ฅผ 1D list๋กœ ์ „ํ™˜ํ•˜๋Š” ๋ฐฉ์‹์„ 'flattening'์ด๋ผ๊ณ  ํ•œ๋‹ค 1. itertools์˜ chain ํ•จ์ˆ˜ ์‚ฌ์šฉํ•˜๊ธฐ import itertools List_2D = [['a','b','c'],[1,2,3],['d',4,'e']] #List to be flattened List_flat = list(itertools.chain(*List_2D)) print("Original List:",List_2D) print("Flattened List:",List_flat) # print๋ฌธ ์ถœ๋ ฅ๊ฒฐ๊ณผ # Original List: [['a', 'b..

Computer Science 2021.04.22

ํŒŒ์ด์ฌ ๊ฐ€์ƒํ™˜๊ฒฝ ๋งŒ๋“ค๊ธฐ (python)

#python ๊ฐ€์ƒํ™˜๊ฒฝ ๋งŒ๋“ค๊ธฐ #๊ฐ€์ƒํ™˜๊ฒฝ์— jupyter notebook์„ค์น˜ #ํŒŒ์ด์ฌ ๊ฐ€์ƒํ™˜๊ฒฝ์— ์ฅฌํ”ผํ„ฐ๋…ธํŠธ๋ถ ์„ค์น˜ 1. ๊ฐ€์ƒํ™˜๊ฒฝ ๋งŒ๋“ค๊ธฐpython3 -m venv ๊ฐ€์ƒํ™˜๊ฒฝ_์ด๋ฆ„ 2. ๊ฐ€์ƒํ™˜๊ฒฝ ํ™œ์„ฑํ™”source ๊ฐ€์ƒํ™˜๊ฒฝ_์ด๋ฆ„/bin/activate pip ๋กœ ํŒจํ‚ค์ง€ ๊ด€๋ฆฌpip ๋ผ๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์‚ฌ์šฉํ•˜์—ฌ ํŒจํ‚ค์ง€๋ฅผ ์„ค์น˜, ์—…๊ทธ๋ ˆ์ด๋“œ ๋ฐ ์ œ๊ฑฐํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.pip ๋Š” "search", "install", "uninstall", "freeze" ๋“ฑ ๋งŽ์€ ๋ถ€์† ๋ช…๋ น์„ ๊ฐ–๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค ์ฐธ๊ณ  :https://docs.python.org/ko/3/tutorial/venv.html jupyter notebook ์— ๊ฐ€์ƒํ™˜๊ฒฝ ์ถ”๊ฐ€(์ฐธ๊ณ ) https://medium.com/@5eo1ab/jupyter-notebook์—-๊ฐ€์ƒํ™˜๊ฒฝ-..

728x90
๋ฐ˜์‘ํ˜•