Notice
Recent Posts
Recent Comments
ยซ   2024/11   ยป
์ผ ์›” ํ™” ์ˆ˜ ๋ชฉ ๊ธˆ ํ† 
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
Tags more
Archives
Today
Total
๊ด€๋ฆฌ ๋ฉ”๋‰ด

๐ŸŒฒ์ž๋ผ๋‚˜๋Š”์ฒญ๋…„

[python] ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค ์™„์ฃผํ•˜์ง€ ๋ชปํ•œ ์„ ์ˆ˜ ๋ณธ๋ฌธ

์•Œ๊ณ ๋ฆฌ์ฆ˜ ๋ฌธ์ œํ’€์ด

[python] ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค ์™„์ฃผํ•˜์ง€ ๋ชปํ•œ ์„ ์ˆ˜

JihyunLee 2019. 10. 29. 16:15
๋ฐ˜์‘ํ˜•

์™„์ฃผํ•˜์ง€ ๋ชปํ•œ ์„ ์ˆ˜

ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค์˜ ์™„์ฃผํ•˜์ง€ ๋ชปํ•œ ์„ ์ˆ˜ ๋ฌธ์ œ๋ฅผ ํŒŒ์ด์ฌ ์ฝ”๋“œ๋กœ ํ’€์–ด๋ณด์•˜๋‹ค.

collections ํด๋ž˜์Šค๋ฅผ ์‚ฌ์šฉํ•˜๋‹ˆ ์•„์ฃผ ํŽธํ•˜๊ฒŒ ํ’€ ์ˆ˜ ์žˆ์—‡๋‹ค.

 

๋‚˜์˜ ์ฝ”๋“œ : 

import collections


participant = ["leo", "kiki", "eden"]
completion = ["kiki", "eden"]
answer = ''

p = collections.Counter(participant)
c = collections.Counter(completion)

print(p-c)
answer = list((p-c).keys())

return answer[0]

 

collections.Counter์— ๋Œ€ํ•œ ๊ณต๋ถ€๋Š” ์—ฌ๊ธฐ์„œ ํ•  ์ˆ˜ ์žˆ์—ˆ๋‹ค.

https://excelsior-cjh.tistory.com/94

๋ฐ˜์‘ํ˜•