๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
๐Ÿ‘จ๐Ÿผ‍๐Ÿ’ป๊ฐœ๋ฐœ/ํŒŒ์ด์ฌ

ํŒŒ์ด์ฌ - ๋‘ ๊ฐœ ์ด์ƒ ์ค‘๋ณต๋œ ๋ฆฌ์ŠคํŠธ ์š”์†Œ ์ถœ๋ ฅ(count)

by Janger 2022. 8. 31.
728x90
๋ฐ˜์‘ํ˜•
lis = ['a', 'b', 'c', 'd', 'd']
for (index, value) in enumerate(lis):
    if lis.count( lis[index] ) >= 2:
        print(index, value)

 

์ฐธ๊ณ : 

https://infinitt.tistory.com/78

 

ํŒŒ์ด์ฌ(python) ๋ฆฌ์ŠคํŠธ ์ค‘๋ณต ์š”์†Œ ๊ฐœ์ˆ˜ ์ฐพ๊ธฐ (์นด์šดํŒ…) or ์ œ๊ฑฐ,์‚ญ์ œํ•˜๊ธฐ (try , except , count)

*์ค‘๋ณต์š”์†Œ ์นด์šดํŒ…ํ•˜๊ธฐ *try, except ๋ฌธ ์‚ฌ์šฉ count={} lists = ["a","a","b",'apple','w','wf'] for i in lists: try: count[i] += 1 except: count[i]=1 print(count) ๊ฒฐ๊ณผ๊ฐ’ : {'a': 2, 'b': 1, 'apple': 1, 'w'..

infinitt.tistory.com

 

728x90
๋ฐ˜์‘ํ˜•