Решая задания на Codewars наткнулся на такую задачу:
Please write a function that will take a string as input and return a hash. The string will be formatted as such. The key will always be a symbol and the value will always be an integer.
"a=1, b=2, c=3, d=4"
This string should return a hash that looks like
{ 'a': 1, 'b': 2, 'c': 3, 'd': 4}
Мое решение этой задачи:
def str_to_hash(s):
s.split(', ')
s = dict([tuple(i.split('=')) for i in s])
s = {k:int(v) for k,v in s.items()}
return s
Выводит ошибку:
ValueError: dictionary update sequence element #0 has length 1; 2 is required
Подскажите, что я делаю не так?