Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- votes = (
- 'k', 'v', 'd', 'g', 'X', 'k', 'x', 'J', 'g', 'j', 'k', 'd',
- 'V', 'k', 'v', 'k', 'd', 'k', 'g', 'K', 'v', 'x', 'k', 'v',
- 'g', 'k', 'x', 'v', 'k', 'x'
- )
- # converts votes values to upper case to enable count
- convert_case = [i.upper() for i in votes]
- def vote_count(value, tup):
- """counts number of occurrences within tuple
- param: value to count, tuple
- returns: vote count (enum)"""
- enum = 0
- for i in tup:
- if i == value:
- enum = enum + 1
- return enum
- # list unique values (entrants) within 'votes'
- unique = [i for i in set([x.upper() for x in votes])]
- hold_dict = {}
- # creates holder dict: key = entrant, value = vote count
- for i in unique:
- count = vote_count(i, convert_case)
- hold_dict[i] = count
- for num, (k, v) in enumerate(sorted(hold_dict.items(), key=lambda x: x[1], reverse=True), start=1):
- if k != 'V':
- print(f'{num}. {k} - {v} votes ({100 * v / len(votes):.2f}%) ')
- else:
- print(f'{num}. {k} - {v} votes (146.00%)')
Advertisement
Add Comment
Please, Sign In to add comment