Sort by

recency

|

1290 Discussions

|

  • + 0 comments
    from collections import Counter
    
    if __name__ == '__main__':
        for common in Counter(sorted(input())).most_common(3):
            print (common[0],common[1])
    
  • + 0 comments

    hi guies can use:

    if __name__ == '__main__':
        s = input()
    
        l = sorted( map(lambda x: (x,s.count(x)),set(s)), 
                    key=lambda x: (-x[1],x[0]))
    
        l = map(lambda x: str(x[0])+" "+str(x[1]),l[:3])
        print('\n'.join(l))
    
  • + 0 comments

    def count(s): s = sorted(s) count_letters = {} for char in s: count_letters[char] = count_letters.get(char, 0)+1 arr = sorted(count_letters.items(), key=lambda x: x[1] , reverse=True)

    for i in range(3):
        print(arr[i][0], arr[i][1])
    

    if name == 'main': count(input())

  • + 0 comments

    Did all the work in one line: s = Counter(sorted(list(input()))).most_common(3)

    Still needed two lines to print the output: for i in s: print(i[0], i[1])

    But basically the line takes the input(), puts the letters in a list, sorts them, then makes them a counter and takes the top 3 most common. Because the Counter takes the first from the list if the counts match, it is in alphabetical order as it counts.

  • + 0 comments

    Here is HackerRank Company Logo in python solution - https://programmingoneonone.com/hackerrank-company-logo-solution-in-python.html