替换字典中每个键和值中的特定字符串
所以我有一个包含 URL 和名称的字典。 URL 地址开始下载,名称包括目录、我想要的文件名称和 .pdf。我的原始列表仅包含一个开始日期,我想编写一个函数,以便我可以更改下载日期并命名接下来的几个月。
def replace_date(dictionary):
desired_date = str(input('Please enter the 3 letter date you need, capitalizing the first letter: '))
for name, location in dictionary.items():
name.replace('Feb', desired_date)
location.replace('Feb', desired_date)
print(dictionary)
当我运行此函数时,字典的打印语句在字典的键和值中仍然具有相同的月份。我想我可能需要将它们保存在 for 循环中,就像我在下面所做的那样,但这并没有改变任何东西。
name = name.replace('Feb', desired_date)
location = location.replace('Feb',desired_date)
一些帮助将不胜感激。
So I have a dictionary that contains URLs and names. The URL addresses start a download and the names include the directory, name I want the file to be, and .pdf. My original list only contains a start date, of which I want to write a function such that I can change the date to download and name the next months.
def replace_date(dictionary):
desired_date = str(input('Please enter the 3 letter date you need, capitalizing the first letter: '))
for name, location in dictionary.items():
name.replace('Feb', desired_date)
location.replace('Feb', desired_date)
print(dictionary)
When I run this function, the print statement of the dictionary still has the same month in both keys and values of my dictionary. I thought it might be that I needed to save them in the for loop like I did below but that didn't change anything.
name = name.replace('Feb', desired_date)
location = location.replace('Feb',desired_date)
Some help would be much appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论