-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlist.py
33 lines (27 loc) · 1.28 KB
/
list.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# This block of code changes the year on a list of dates.
# The "years" list is given with existing elements.
years = ["January 2023", "May 2025", "April 2023", "August 2024", "September 2025", "December 2023"]
# The variable "updated_years" is initialized as a list data type
# using empty square brackets []. This list will hold the new list
# with the updated years.
updated_years = []
# The for loop checks each "year" element in the list "years".
for year in years:
# The if-statement checks if the "year" element ends with the
# substring "2023".
if year.endswith("2023"):
# If True, then a temporary variable "new" will hold the
# modified "year" element where the "2023" substring is
# replaced with the substring "2024".
new = year.replace("2023","2024")
# Then, the list "updated_years" is appended with the changed
# element held in the temporary variable "new".
updated_years.append(new)
# If False, the original "year" element will be appended to the
# the "updated_years" list unchanged.
else:
updated_years.append(year)
print(updated_years)
# Should print ["January 2024", "May 2025", "April 2024", "August 2024", "September 2025", "December 2024"]
# mayur kyatham
#mayur kyatham