๐/Python
-
2๊ฐ์ ๋์ ๋๋ฆฌ์์, ์ค๋ณต๋ ํค ๊ฐ์ ๊ฐ์ง ๋ฐ์ดํฐ๋ ๊ฐ์ ํฉ์น๊ณ , ์ ์ฒด ๋ฐ์ดํฐ๋ฅผ ํฉ์ณ์ ์ถ๋ ฅํ๋ ํจ์ dict_first = {'์ฌ๊ณผ':30, '๋ฐฐ':15, '๊ฐ':10, 'ํฌ๋':10} dict_second = {'์ฌ๊ณผ':5, '๊ฐ':25, '๋ฐฐ':15, '๊ทค':25} def merge_dict(dict_first, dict_second): # TODO #์ถ๋ ฅ {'๊ฐ':35, '๊ทค':25, '๋ฐฐ':30, '์ฌ๊ณผ':35, 'ํฌ๋':10} dict_first = {'์ฌ๊ณผ':30, '๋ฐฐ':15, '๊ฐ':10, 'ํฌ๋':10} dict_second = {'์ฌ๊ณผ':5, '๊ฐ':25, '๋ฐฐ':15, '๊ทค':25} def merge_dict(dict_first, dict_second): dict_all = dict..
[Python] ๋ ๊ฐ์ ๋์ ๋๋ฆฌ ๊ฐ์ฒด๋ฅผ ํฉ์ณ์ ์ถ๋ ฅํ๊ธฐ2๊ฐ์ ๋์ ๋๋ฆฌ์์, ์ค๋ณต๋ ํค ๊ฐ์ ๊ฐ์ง ๋ฐ์ดํฐ๋ ๊ฐ์ ํฉ์น๊ณ , ์ ์ฒด ๋ฐ์ดํฐ๋ฅผ ํฉ์ณ์ ์ถ๋ ฅํ๋ ํจ์ dict_first = {'์ฌ๊ณผ':30, '๋ฐฐ':15, '๊ฐ':10, 'ํฌ๋':10} dict_second = {'์ฌ๊ณผ':5, '๊ฐ':25, '๋ฐฐ':15, '๊ทค':25} def merge_dict(dict_first, dict_second): # TODO #์ถ๋ ฅ {'๊ฐ':35, '๊ทค':25, '๋ฐฐ':30, '์ฌ๊ณผ':35, 'ํฌ๋':10} dict_first = {'์ฌ๊ณผ':30, '๋ฐฐ':15, '๊ฐ':10, 'ํฌ๋':10} dict_second = {'์ฌ๊ณผ':5, '๊ฐ':25, '๋ฐฐ':15, '๊ทค':25} def merge_dict(dict_first, dict_second): dict_all = dict..
2022.01.21 -
์ ๋ ฅ๋ฐ์ ๋ฌธ์์ด์์ ์ซ์๋ฅผ ์ ๊ฑฐํ๊ณ , ๋ฌธ์์ด์ ๋ฆฌ์คํธ๋ก ๋ณํํ์ฌ ์ถ๋ ฅํ๋ ํจ์ def find_string(inputs) # TODO #์ถ๋ ฅ ์์ inputs = "cat32dog16cow5" string_list = find_string(inputs) print(string_list) #์ถ๋ ฅ ["cat", "dog", "cow"] inputs = "cat32dog16cow5" def find_string(inputs): str = "" for i in inputs: if (not(i.isdigit())): str += i else: str += " " return str.split() print(find_string(inputs)) *isdigit ํจ์: + ์ฐธ๊ณ *split ํจ์: + ์ฐธ๊ณ
[Python] ์ ๋ ฅ๋ฐ์ ๋ฌธ์์ด์์ ์ซ์ ์ ๊ฑฐํ๊ธฐ์ ๋ ฅ๋ฐ์ ๋ฌธ์์ด์์ ์ซ์๋ฅผ ์ ๊ฑฐํ๊ณ , ๋ฌธ์์ด์ ๋ฆฌ์คํธ๋ก ๋ณํํ์ฌ ์ถ๋ ฅํ๋ ํจ์ def find_string(inputs) # TODO #์ถ๋ ฅ ์์ inputs = "cat32dog16cow5" string_list = find_string(inputs) print(string_list) #์ถ๋ ฅ ["cat", "dog", "cow"] inputs = "cat32dog16cow5" def find_string(inputs): str = "" for i in inputs: if (not(i.isdigit())): str += i else: str += " " return str.split() print(find_string(inputs)) *isdigit ํจ์: + ์ฐธ๊ณ *split ํจ์: + ์ฐธ๊ณ
2022.01.21 -
ํํ์ ์์๋ก ๊ฐ์ง๊ณ ์๋ ๋ฆฌ์คํธ์์, ๊ฐ ํํ์ ํ๊ท ์ ์ถ๋ ฅํ๋ ํจ์ score = [(100, 100), (95, 90), (55, 60), (75, 80), (70, 70)] def get_avg(score): # TODO #์ถ๋ ฅ 1 ๋ฒ, ํ๊ท : 100.0 ์ 2 ๋ฒ, ํ๊ท : 92.5 ์ 3 ๋ฒ, ํ๊ท : 57.5 ์ 4 ๋ฒ, ํ๊ท : 77.5 ์ 5 ๋ฒ, ํ๊ท : 70.0 ์ score = [(100, 100), (95, 90), (55, 60), (75, 80), (70, 70)] def get_avg(score): list1 = [x[0] for x in score] list2 = [x[1] for x in score] for i in range(len(list1)): print("{} ๋ฒ..
[Python] ํํ์ ์์๋ก ๊ฐ์ง ๋ฆฌ์คํธ ๊ฐ ์ถ์ถํ๊ธฐํํ์ ์์๋ก ๊ฐ์ง๊ณ ์๋ ๋ฆฌ์คํธ์์, ๊ฐ ํํ์ ํ๊ท ์ ์ถ๋ ฅํ๋ ํจ์ score = [(100, 100), (95, 90), (55, 60), (75, 80), (70, 70)] def get_avg(score): # TODO #์ถ๋ ฅ 1 ๋ฒ, ํ๊ท : 100.0 ์ 2 ๋ฒ, ํ๊ท : 92.5 ์ 3 ๋ฒ, ํ๊ท : 57.5 ์ 4 ๋ฒ, ํ๊ท : 77.5 ์ 5 ๋ฒ, ํ๊ท : 70.0 ์ score = [(100, 100), (95, 90), (55, 60), (75, 80), (70, 70)] def get_avg(score): list1 = [x[0] for x in score] list2 = [x[1] for x in score] for i in range(len(list1)): print("{} ๋ฒ..
2022.01.20 -
๋ฌธ์์ด์ ๋จ์ด ๋จ์๋ก ์ญ์์ผ๋ก ์ถ๋ ฅํ๋ ํจ์ sentence = "You make me wanna run it all back" def reverse_sentence(sentence): # TODO print(reverse_sentence(sentence)) #์ถ๋ ฅ Back all it run wanna me make You ๋ฌธ์ ์์ฒด๋ ์๋ ๋ฌธ์ ์ ๋น์ทํ์ง๋ง, 2022.01.19 - [๋ฌธ์ /Python] - [Python] ๋ฌธ์์ด ๋ค์ง๊ธฐ/๋ฌธ์์ด ๊ฑฐ๊พธ๋ก ์ถ๋ ฅํ๊ธฐ [Python] ๋ฌธ์์ด ๋ค์ง๊ธฐ/๋ฌธ์์ด ๊ฑฐ๊พธ๋ก ์ถ๋ ฅํ๊ธฐ ๋ฌธ์์ด์ ๊ฑฐ๊พธ๋ก ์ถ๋ ฅํ๋ ํจ์ sentence = "i want you, eat me like a main dish" def reverse_sentence(sentence): # TODO pr..
[Python] ๋ฌธ์์ด ๋จ์ด ๋จ์๋ก ์ญ์์ผ๋ก ์ถ๋ ฅํ๊ธฐ๋ฌธ์์ด์ ๋จ์ด ๋จ์๋ก ์ญ์์ผ๋ก ์ถ๋ ฅํ๋ ํจ์ sentence = "You make me wanna run it all back" def reverse_sentence(sentence): # TODO print(reverse_sentence(sentence)) #์ถ๋ ฅ Back all it run wanna me make You ๋ฌธ์ ์์ฒด๋ ์๋ ๋ฌธ์ ์ ๋น์ทํ์ง๋ง, 2022.01.19 - [๋ฌธ์ /Python] - [Python] ๋ฌธ์์ด ๋ค์ง๊ธฐ/๋ฌธ์์ด ๊ฑฐ๊พธ๋ก ์ถ๋ ฅํ๊ธฐ [Python] ๋ฌธ์์ด ๋ค์ง๊ธฐ/๋ฌธ์์ด ๊ฑฐ๊พธ๋ก ์ถ๋ ฅํ๊ธฐ ๋ฌธ์์ด์ ๊ฑฐ๊พธ๋ก ์ถ๋ ฅํ๋ ํจ์ sentence = "i want you, eat me like a main dish" def reverse_sentence(sentence): # TODO pr..
2022.01.19 -
๊ฐ๋จํ ํจ์๊ฑฐ๋, ํ ๋ฒ๋ง ์ฌ์ฉํ๋ ์ผํ์ฑ ํจ์์ธ ๊ฒฝ์ฐ def๋ก ํจ์๋ฅผ ์ ์ํ๋ ๊ฒ๋ณด๋ค ํธ๋ฆฌํ๊ฒ ์ฌ์ฉํ ์ ์๋ ๋ฐฉ๋ฒ lambda ์ธ์ : ํํ์ ex. ์ง์ ํ๋ณ ํจ์ # ์ผ๋ฐ ํจ์ def Is_even(x): return x % 2 == 0 #lambda ํจ์ Is_even = lambda x : x % 2 == 0
[Python] lambda ํจ์๊ฐ๋จํ ํจ์๊ฑฐ๋, ํ ๋ฒ๋ง ์ฌ์ฉํ๋ ์ผํ์ฑ ํจ์์ธ ๊ฒฝ์ฐ def๋ก ํจ์๋ฅผ ์ ์ํ๋ ๊ฒ๋ณด๋ค ํธ๋ฆฌํ๊ฒ ์ฌ์ฉํ ์ ์๋ ๋ฐฉ๋ฒ lambda ์ธ์ : ํํ์ ex. ์ง์ ํ๋ณ ํจ์ # ์ผ๋ฐ ํจ์ def Is_even(x): return x % 2 == 0 #lambda ํจ์ Is_even = lambda x : x % 2 == 0
2022.01.19 -
iterator๊ฐ๋ค์ ํ๋ํ๋ function์ ์ ์ฉํ์ฌ ๋ฐํ๊ฐ์ด true์ธ ๊ฐ์ ํํฐ๋งํ์ฌ ๋ค์ ๋ฆฌ์คํธ๋ก ๋ง๋ค์ด์ฃผ๋ ํจ์ filter(function, iterator) *function: ํํฐ๋ง์ ์ ์ฉ์ํฌ ํจ์ *iterator: ๋ฐ๋ณต๊ฐ๋ฅํ ๊ฐ *๋ฐํ ๊ฐ์ด filter ๊ฐ์ฒด์ด๊ธฐ ๋๋ฌธ์ ๋ฆฌ์คํธ๋ก ํ๋ณํํด์ผํ๋ค. list(filter(ํจ์, ๋ฆฌ์คํธ)) ex. ๋ฆฌ์คํธ์์ ํ์ ์์๋ง ์ถ๋ ฅ #์ฃผ์ด์ง ๋ฆฌ์คํธ num_list = {1, 5, 7, 15, 16, 22, 28, 29} def get_odd(n): return [n % 2 == 1] odd_list = list(filter(get_odd, num_list)) print(odd_list) #์ถ๋ ฅ [1, 5, 7, 15, 29] +lambda ํจ์ ์ฌ์ฉ..
[Python] filter ํจ์iterator๊ฐ๋ค์ ํ๋ํ๋ function์ ์ ์ฉํ์ฌ ๋ฐํ๊ฐ์ด true์ธ ๊ฐ์ ํํฐ๋งํ์ฌ ๋ค์ ๋ฆฌ์คํธ๋ก ๋ง๋ค์ด์ฃผ๋ ํจ์ filter(function, iterator) *function: ํํฐ๋ง์ ์ ์ฉ์ํฌ ํจ์ *iterator: ๋ฐ๋ณต๊ฐ๋ฅํ ๊ฐ *๋ฐํ ๊ฐ์ด filter ๊ฐ์ฒด์ด๊ธฐ ๋๋ฌธ์ ๋ฆฌ์คํธ๋ก ํ๋ณํํด์ผํ๋ค. list(filter(ํจ์, ๋ฆฌ์คํธ)) ex. ๋ฆฌ์คํธ์์ ํ์ ์์๋ง ์ถ๋ ฅ #์ฃผ์ด์ง ๋ฆฌ์คํธ num_list = {1, 5, 7, 15, 16, 22, 28, 29} def get_odd(n): return [n % 2 == 1] odd_list = list(filter(get_odd, num_list)) print(odd_list) #์ถ๋ ฅ [1, 5, 7, 15, 29] +lambda ํจ์ ์ฌ์ฉ..
2022.01.19