Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Dictionary Basics
#3
Hi and thanks for the input. So, I reverted back to where I was to begin this post and took your suggestion to initialize with an empty dictionary as follows(please ignore all the comments):

reader=csv.reader(Holiday_File)
Holiday_DICT={}
#Holiday_DICT={'Holiday':1/1/1900,'Dayofwk':"Sunday",'Desc':"dummy",'Daystoadd':1,'Daystosubtract':-1}
#Holiday_DICT={'Holiday':1/1/1900,(['Dayofwk','Desc','Daystoadd','Daystosubtract'])}
x=0
for row in reader:
    #print(row[0],row[1],row[2],row[3],row[4])
    item=row[0]
    #x=0
    #Holiday_DICT[item]=row[0],row[1],row[2],row[3],row[4]
    #Holiday=row[0]
    #Dayofwk=row[1]
    #Desc=row[2]
    #Daystoadd=row[3]
    #Daystosubtract=row[4]
    Holiday_DICT[item]=row[0],row[1],row[2],row[3],row[4]
    #Holiday_DICT[Holiday]=Holiday
    #Holiday_DICT[Dayofwk]=Dayofwk
    #Holiday_DICT[Desc]=Desc
    #Holiday_DICT[Daystoadd]=Daystoadd
    #Holiday_DICT[Daystosubtract]=Daystosubtract
    #x=x+row
    #print("x: ", x)
Holiday_File.close()
Here are the results:
{'20160101': ('20160101', 'Friday', "New Year's Day", '1', '-1'), '20160118': ('20160118', 'Monday', 'Martin Luther King Jr. Day', '1', '-1'), '20160216': ('20160216', 'Monday', "Washington's Birthday", '1', '-1'), '20160325': ('20160325', 'Friday', 'Good Friday', '2', '-1'), '20160530': ('20160530', 'Monday', 'Memorial Day', '1', '-1'), '20160704': ('20160704', 'Monday', 'Independence Day', '1', '-1'), '20160905': ('20160905', 'Monday', 'Labor Day', '1', '-1'), '20161124': ('20161124', 'Thursday', 'Thanksgiving Day', '1', '-2'), '20161225': ('20161225', 'Sunday', 'Christmas Day', '2', '-1'), '20170102': ('20170102', 'Monday', '1- JAN (Observed Monday, January 2)', '1', '-1'), '20170116': ('20170116', 'Monday', 'Monday, January 16', '1', '-1'), '20170220': ('20170220', 'Monday', 'Monday, February 20', '1', '-1'), '20170414': ('20170414', 'Friday', 'Friday, April 14', '1', '-1'), '20170529': ('20170529', 'Monday', 'Monday, May 29', '2', '-2'), '20170704': ('20170704', 'Tuesday', 'Tuesday, July 4*', '1', '-1'), '20170904': ('20170904', 'Monday', 'Monday, September 4', '1', '-1'), '20171123': ('20171123', 'Thursday', 'Thursday, November 23**', '1', '-1'), '20171225': ('20171225', 'Monday', 'Monday, December 25', '1', '-1'), '20180101': ('20180101', 'Monday', 'New Years Day', '1', '-1'), '20180115': ('20180115', 'Monday', 'Martin Luther King, Jr. Day', '1', '-1'), '20180219': ('20180219', 'Monday', "Washington's Birthday", '1', '-1'), '20180330': ('20180330', 'Friday', 'Good Friday', '1', '-1')....more}

This looks pretty good, but I guess I'd like to know what has actually been created. I have a KEY of that date referenced above, then the other attributes lumped together within () which looks like a LIST as maybe the VALUE of that date KEY??? Is that right?? I don't think it's created a DICT within a DICT or has it? Just trying to learn what's what even though I think I could make these results work, one way or another.

Again thanks.
Reply


Messages In This Thread
Dictionary Basics - by pythonjm - Nov-26-2018, 02:12 PM
RE: Dictionary Basics - by ichabod801 - Nov-26-2018, 05:37 PM
RE: Dictionary Basics - by pythonjm - Nov-26-2018, 08:26 PM
RE: Dictionary Basics - by ichabod801 - Nov-26-2018, 08:34 PM
RE: Dictionary Basics - by Gribouillis - Nov-26-2018, 09:56 PM
RE: Dictionary Basics - by pythonjm - Nov-26-2018, 11:11 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Learned Python Basics, what now? muzikman 20 6,259 Oct-11-2021, 01:34 AM
Last Post: Underscore
  PYserial basics? bako 10 5,195 Apr-26-2020, 09:15 PM
Last Post: bowlofred
  [split] Debugging scripts basics tultalk 5 3,145 Apr-25-2020, 01:02 AM
Last Post: menator01
  Debugging scripts basics bako 8 3,599 Apr-24-2020, 06:18 AM
Last Post: Larz60+
  Problem with basics Wraith2102 2 2,028 Jun-17-2019, 06:51 PM
Last Post: perfringo
  What to do after learning python basics xyzabc12310000 1 2,874 May-20-2018, 11:43 PM
Last Post: micseydel

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020