Hi there i have a list:
lst = ['Bedroom,24', 'Bedroom,26', 'Kitchen,22', 'Kitchen,23', 'Living Room,23', 'Living Room,24', 'Living Room,25']
Now i can't think of any way that i can change this to dictionary:
lst = {'temp':24,.....}
I tried replacing the comma but it didn't work out since its a list. I used for loops but didnt seem to work, plus i am a begginer and i didnt know how to change the number into integers.The example below makes the list:
fname = open("temps1.txt")
lst = []
for line in fname:
line = line.rstrip()
words = line.splitlines()
for word in words:
if word in lst: continue
lst = lst + words
lst.sort()
print(lst)
>>>>>>['temp,24', 'bedroom,26', 'class,23'] #output
At the end, Is it possible to covert the list into the dictionary?
My output should be:
Average temp:
bedroom: #value
living room:#value
and so on