This is a Pandas solution involving a 4-space delimiter.
import pandas as pd
from io import StringIO
mystr = StringIO("""Barcelona 2015,2016,2017
Real Madrid 2010
Napoli 2007,2009
Bayern Munich 2008,2009,2010,2011,2012,2013""")
df = pd.read_csv(mystr, delimiter=' ', header=None, names=['Club', 'Years'])
df['Years'] = [list(map(int, x)) for x in df['Years'].str.split(',')]
d = df.set_index('Club')['Years'].to_dict()
Result
{'Barcelona': [2015, 2016, 2017],
'Bayern Munich': [2008, 2009, 2010, 2011, 2012, 2013],
'Napoli': [2007, 2009],
'Real Madrid': [2010]}
Explanation
- Read the file with the appropriate separator and name columns.
- Separate by comma and map each element to an integer type through list comprehension.
- , ,
.to_dict() .