[Tutor] creating variable names from string slices
Tue Apr 1 08:07:02 2003
> Betty Blonde Student
> Veronica Brunette Student
> What I want to do is define a function that gets passed each line, and
> returns a dictionary with the first element as the name, and
> the subsequent elements as the key:value pairs:
Split the line then assign the firstvelement as the key and the rest as the
words = line.split()
data[words] = words[1:]
> How do I make this trick work?
Split the string rather than using slicing. You probably want to strip()
any whitespace off the words before inserting them too...
Author of the Learn to Program website