[Tutor] List vs. Set:

James Lundy jamesalundy at hotmail.com
Sat Feb 24 15:00:58 EST 2018


To whom it may concern. This code is from Dr. John Keyser.


gooddata = []

for singleday in datalist:
    if (singleday[0] == day) and (singleday[1] == month):
        gooddata.append({singleday[2], singleday[3], singleday[4], singleday[5]})

# Perform analysis
minsofar = 120
maxsofar = -100
numgooddates = 1
sumofmin = 0
sumofmax = 0

# so singleday in datalist is a list while singleday in gooddata is a set?????????

for singleday in gooddata:

    sumofmin += singleday[1]
    sumofmax += singleday[2]
    if singleday[1] < minsofar:
        minsofar = singleday[1]
    if singleday[2] > maxsofar:
        maxsofar = singleday[2]

Could this be a bug in my Pycharm 3 compiler I have had mixed experiences running the code.

An insertion of a space after for singleday in gooddata: line 54 caused the program to run as desired, once, since other runs cause the error


Traceback (most recent call last):

  File "C:/Users/Dad/PycharmProjects/TopDownDesign/WeatherDataSpecialDay.py", line 56, in <module>

    sumofmin += singleday[1]

TypeError: 'set' object does not support indexing

persist.

I will attach the code and test file. Please allow me to thank you in advance for answering this query. I am new with Python and would appreciate any advice.

God Bless:

James Lundy
jalundy at computer.org<mailto:jalundy at computer.org>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: WeatherDataSpecialDay.py
URL: <http://mail.python.org/pipermail/tutor/attachments/20180224/cb1c4533/attachment.ksh>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: WeatherData.txt
URL: <http://mail.python.org/pipermail/tutor/attachments/20180224/cb1c4533/attachment.txt>


More information about the Tutor mailing list