[Tutor] (no subject)
Alan Gauld
learn2program at gmail.com
Tue Feb 16 12:52:22 EST 2021
Please always use ReplyAll (or reply List if you have that option) on
the tutor list
because otherwise it only goes to the person to whom you are replying.
On 16/02/2021 17:01, ੧ wrote:
> I have tried
>
> string = "Monday - 19, Tuesday - 20"
> Dict = dict((x.strip(), int(y.strip()))
> for x, y in (element.split('-')
> for element in string.split(', ')))
> print(Dict)
>
> and
>
> string = "{'Monday': 19, 'Tuesday':20}"
> Dict = eval(string)
> print(Dict)
>
> Both give error
You are doing far more than you were asked and making life extremely
complex.
All you had to do was write one single line defining a dictionary.
See davbids reply to your original mail.
Also, please don't use eval() its very insecure and hardly ever needed
even by experts.
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos
More information about the Tutor
mailing list