I have a program, but it is not important.
from collections import Counter
def balance(left, right, result = 0):
wages = {'!': 2, '?': 3}
for key in Counter(left).keys():
result += Counter(left).get(key) * wages.get(key)
for key_ in Counter(right).keys():
result -= Counter(right).get(key_) * wages.get(key_)
if result == 0:
return 'Balance'
return 'Left' if result > 0 else 'Right'
Source for interesting: https://www.codewars.com/kata/57fb44a12b53146fe1000136
Is it possible to write this piece of code in one line?
if result == 0:
return 'Balance'
return 'Left' if result > 0 else 'Right'