์ „์ฒด ๊ธ€

Python, C++, Data Science ๊ณต๋ถ€ ๋ธ”๋กœ๊ทธ ์ž…๋‹ˆ๋‹ค.
ยทpython
๋ฌธ์ œ for๋ฌธ ๋‚ด์—์„œ queires ๋‚ด์˜ index๋“ค์„ ๋ฐ˜๋ณต์ ์œผ๋กœ my_string์— ์ ์šฉ์‹œํ‚ค๋ฉด์„œ, ์ ์šฉ๋œ ๋‚ด์šฉ์„ ๋‹ค์‹œ my_string์— ์ €์žฅํ•˜๋Š” ๋ฐฉ์‹์œผ๋กœ ํ•˜๋ฉด ๋  ๊ฒƒ ๊ฐ™๋‹ค. ์ฝ”๋“œ ๋ฐ ์„ค๋ช… def solution(my_string, queries): result = my_string for index in queries: front_string = result[:index[0]] mid_string = result[index[0]: index[1] + 1] back_string = result[index[1] + 1:len(result)] result = front_string + mid_string[::-1] + back_string return result for๋ฌธ ์†์˜ string slicing ..
ยทpython
python์˜ tkinter ๋ชจ๋“ˆ์„ ์‚ฌ์šฉํ•ด์„œ ๋‹จ์œ„ ๋ณ€ํ™˜๊ธฐ๋ฅผ ๋งŒ๋“ค์–ด ๋ณด์ž. ์•„์ง tkinter ๋ชจ๋“ˆ์„ ์ฒ˜์Œ ๊ณต๋ถ€ํ•˜๋Š” ์ค‘์ด๊ธฐ ๋•Œ๋ฌธ์—, ๊ฐ„๋‹จํ•˜๊ฒŒ ๊ตฌํ˜„ํ•ด๋ณด์•˜๋‹ค. 1. miles to km, km to miles 2๊ฐ€์ง€ ์˜ต์…˜ ๊ตฌํ˜„ 2. ๋ฒ„ํŠผ์„ ๋ˆ„๋ฅผ ์‹œ ๊ณ„์‚ฐ์ด ์™„๋ฃŒ๋˜์–ด ์™„๋ฃŒ ๊ฐ’์ด ์ถœ๋ ฅ ์ฝ”๋“œ from tkinter import * window = Tk() FONT = ("Arial", 20) from_unit = "miles" to_unit = "km" window.title("Unit Converter") window.minsize(width="250", height="100") window.config(padx=50, pady=25) # Label from_label = Label(text=f"{from_unit..
ยทpython
*args (arguments) Python ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ•  ๋•Œ, ํ•จ์ˆ˜์— ์ธ์ž(arguments)๊ฐ€ ๋ช‡๊ฐœ ์ž…๋ ฅ๋  ์ง€ ๋ชจ๋ฅด๋Š” ๊ฒฝ์šฐ๊ฐ€ ์ƒ๊ธด๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด, ๊ฐ€์กฑ ๊ตฌ์„ฑ์›์„ ์ž…๋ ฅํ•˜๋ฉด ๊ทธ๋Œ€๋กœ ์ถœ๋ ฅํ•˜๋Š” ํ•จ์ˆ˜๊ฐ€ ์žˆ๋‹ค๋ฉด, ๊ฐœ์ธ๋ณ„๋กœ ๊ฐ€์กฑ์˜ ๊ตฌ์„ฑ์› ์ˆ˜๋Š” ๋‹ค๋ฅด๊ธฐ ๋•Œ๋ฌธ์— ์ธ์ž๊ฐ€ ์ด ๋ช‡๊ฐœ ์ž…๋ ฅ๋ ์ง€๋Š” ์•Œ ์ˆ˜ ์—†๋‹ค. ์„ธ๊ณ„์˜ ๋ชจ๋“  ๊ฐ€์กฑ์ด 4๋ช…์œผ๋กœ๋งŒ ์ด๋ฃจ์–ด์ ธ ์žˆ๋‹ค๋ฉด, ์šฐ๋ฆฌ๊ฐ€ ์•Œ๋˜ ๊ฒƒ ์ฒ˜๋Ÿผ ๋‹ค์Œ๊ณผ ๊ฐ™์ด ํ•จ์ˆ˜๋ฅผ ์งค ์ˆ˜ ์žˆ๋‹ค. def family(dad, mom, sibling, me): print(dad, mom, sibling, me) family("๊น€๋ฒ”์ˆ˜", "์ด์†Œ๋ผ", "๋ฐ•ํšจ์‹ ", "์žฅ๋ฒ”์ค€") # output: ๊น€๋ฒ”์ˆ˜ ์ด์†Œ๋ผ ๋ฐ•ํšจ์‹  ์žฅ๋ฒ”์ค€ ํ•˜์ง€๋งŒ ๋‹น์—ฐํžˆ ์„ธ์ƒ์˜ ๋ชจ๋“  ๊ฐ€์กฑ ๊ตฌ์„ฑ์›์€ ์ˆ˜๊ฐ€ ๋‹ค๋ฅด๊ณ , ์ด๋Ÿด ๊ฒฝ์šฐ *args๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ๋œ๋‹ค. ..
ยทpython
๋ชจ๋‘๊ฐ€ ์•Œ๋‹ค์‹œํ”ผ python์˜ ์žฅ์  ์ค‘ ํ•˜๋‚˜๋Š” ๊ฐ„๋‹จํ•œ ๋ฌธ๋ฒ•์ด๋‹ค. ๋‹ค๋ฅธ ์–ธ์–ด์—์„œ ๋งŽ์€ ์ค„์„ ์‚ฌ์šฉํ•ด์•ผ ๋งŒ๋“ค ์ˆ˜ ์žˆ๋Š” ๋ฆฌ์ŠคํŠธ๋ฅผ ํ•œ ์ค„๋กœ ํ‘œํ˜„ํ•  ์ˆ˜ ์žˆ๋‹ค. list comprehension์„ ์ž˜ ์ด์šฉํ•˜๋ฉด ์ฝ”๋“œ๊ฐ€ ํ›จ์”ฌ ๊ฐ„๊ฒฐํ•˜๊ณ  ์ด๋ป๋ณด์ธ๋‹ค. ์˜ˆ์‹œ๋ฅผ ๋“ค์–ด๋ณด๊ฒ ๋‹ค ์ •์ˆ˜ ๋ฆฌ์ŠคํŠธ๊ฐ€ ์ฃผ์–ด์กŒ์„ ๋•Œ, ๊ฐ ์š”์†Œ์— 1์„ ๋”ํ•œ ์ƒˆ๋กœ์šด ๋ฆฌ์ŠคํŠธ๋ฅผ ๋งŒ๋“ค๊ณ  ์‹ถ์„ ๋•Œ, list comprehension์„ ์ด์šฉํ•˜์ง€ ์•Š์œผ๋ฉด for๋ฌธ์„ ํ™œ์šฉํ•˜์—ฌ ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์ž‘์„ฑํ•  ์ˆ˜ ์žˆ๋‹ค. my_list = [1, 2, 3] new_list = [] for num in my_list: new_list.append(num + 1) print(new_list) # = [2, 3, 4] ํ•˜์ง€๋งŒ, list comprehension์„ ์ด์šฉํ•˜๋ฉด ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์ž‘์„ฑํ•  ์ˆ˜ ์žˆ๋‹ค...
Chan Lee
Chan Code & DS ๐Ÿง‘‍๐Ÿ’ป๐Ÿ“Š