Here we have a list with 2 string values:Yes, I recall getting confused on this page. Once I opened up the link, I recognized it.This
mydata = ['AirTemp', ' 71.73']
is a list
First item in the list, mydata[0] = 'AirTemp'
Second item in the list, mydata [1] = '71.73'
This is a dictionary:
mydata = { 'AirTemp': '71.73'}
mydata['AirTemp'] = '71.73'
There is no mydata['71.73']
See more here: https://www.geeksforgeeks.org/differenc ... in-python/
So [] is a list while {} is a dict? Correct?
Then why would there be a check for a dict in these lines of code:if parts[0] equals HOT_FLUID_TEMP (which is correct) then results{} (It's telling the program that results is now a dict?) but then says to keep [1] which is the numeric value....Am I understanding that at that point, I have a dict of 4 numbers?Code:
if parts[0] == FIRST_LABEL:results = {}results[parts[0]] = parts[1]
Code:
mydata = ['some name', 'some value']
results = {} creates an empty dict.
For this
Code:
results[mydata[0]] = mydata[1]
Code:
results["some name"] = "some value"
Code:
{ "some value" : "some data"}
And that is the main difference between a list and a dict. In a list, you get the value by the items position in the list. But with a dict you use the key to get the value.
Statistics: Posted by memjr — Wed Apr 17, 2024 2:49 am