So I created this code with the help of Stack Overflow users.
def get_name(string):
return string.replace("+", "").replace("-", "")
def gnames(input_list: list):
output = {}
for entry in input_list:
if '->' in entry:
names = entry.split('->')
output[names[1]] = output[names[0]]
output[names[0]] = 0
else:
name = get_name(entry)
if name not in output:
output[name] = 0
if "++" in entry:
output[name] += 1
if "--" in entry:
output[name] -= 1
return output
print(gnames(["Jim--", "John--", "Jordan--", "Jim++", "John--", "Jeff--", "June++", "June->Jim"]))
and this returns
{'Jim': 1, 'John': -2, 'Jordan': -1, 'Jeff': -1, 'June': 0}
Now this is right, but I want gnames()
to return only the non zero values negative numbers or positive numbers are fine
so in my example, there's 'June' = 0
and I want the output of gnames()
to exclude 'June' = 0
or if any other person has a 0... I want gnames()
to exclude it...
so my output in thiscase, should return
{'Jim': 1, 'John': -2, 'Jordan': -1, 'Jeff': -1}
How can I do that??