Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Unable to Loop Over Date
#3
Examples:

#! /usr/bin/env python3

from datetime import date

my_dates = {"Jane": str(date(1994, 12, 25)), "Daniel": str(date(2000, 11, 13)), "George": str(date(1971, 9, 27))}

text = 'Using key, value pair'
print(f'{text}')
print('-'*len(text))
for name, date in my_dates.items():
    print(f'Name: {name} Date: {date}')
print()

text = 'Using only key'
print(text)
print('-'*len(text))
for name in my_dates.keys():
    print(f'Name: {name}')
print()

text = 'Using only value'
print(text)
print('-'*len(text))
for date in my_dates.values():
    print(f'Date: {date}')
Output:
Using key, value pair --------------------- Name: Jane Date: 1994-12-25 Name: Daniel Date: 2000-11-13 Name: George Date: 1971-09-27 Using only key -------------- Name: Jane Name: Daniel Name: George Using only value ---------------- Date: 1994-12-25 Date: 2000-11-13 Date: 1971-09-27
I welcome all feedback.
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags


Reply


Messages In This Thread
Unable to Loop Over Date - by gdbengo - Jan-09-2022, 03:55 PM
RE: Unable to Loop Over Date - by ndc85430 - Jan-09-2022, 04:23 PM
RE: Unable to Loop Over Date - by menator01 - Jan-09-2022, 05:11 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Compare current date on calendar with date format file name Fioravanti 1 366 Mar-26-2024, 08:23 AM
Last Post: Pedroski55
  Python date format changes to date & time 1418 4 782 Jan-20-2024, 04:45 AM
Last Post: 1418
  Date format and past date check function Turtle 5 4,505 Oct-22-2021, 09:45 PM
Last Post: deanhystad
  How to add previous date infront of every unique customer id's invoice date ur_enegmatic 1 2,307 Feb-06-2021, 10:48 PM
Last Post: eddywinch82
  Unable to print stuff from while loop Nick1507 4 2,455 Sep-17-2020, 02:26 PM
Last Post: Nick1507
  How to add date and years(integer) to get a date NG0824 4 2,973 Sep-03-2020, 02:25 PM
Last Post: NG0824
  Unable to pass date timestamp as Parameters : nagu4651 1 1,862 Jun-22-2020, 06:07 PM
Last Post: Larz60+
  Unable to combine print statements in for loop adeana 2 2,075 Jun-12-2020, 05:08 PM
Last Post: adeana
  Unable to execute the for loop harold 1 1,787 Sep-23-2019, 12:27 PM
Last Post: buran
  Substracting today's date from a date in column of dates to get an integer value firebird 1 2,186 Jul-04-2019, 06:54 PM
Last Post: Axel_Erfurt

Forum Jump:

User Panel Messages

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