-1
>>> list_a = ['a', 'b', 'c', 'c']
>>> get_repeated(list_a)
['c']

What would be the most pythonic way to do function get_repeated()?

  • 2
    did you try anything youselft to get that? – A l w a y s S u n n y Sep 12 '22 at 10:11
  • Welcome to Stack Overflow. Please read [the help pages](http://stackoverflow.com/help), take the SO [tour], read [ask], as well as [this question checklist](https://codeblog.jonskeet.uk/2012/11/24/stack-overflow-question-checklist/). Lastly please learn how to create a [mre] of ***your own*** attempt. – Some programmer dude Sep 12 '22 at 10:30
  • `list(set([i for i in list_a if list(list_a).count(i) > 1]))` – uozcan12 Sep 12 '22 at 12:51

1 Answers1

2

this should work

from collections import Counter

list_a = ['a', 'b', 'c', 'c']
count = Counter(list_a)
output = [key for key, val in count.items() if val > 1]
print(output)
>>> ['c']
Lucas M. Uriarte
  • 2,403
  • 5
  • 19