Question
The following dictionary of dates and stock prices is defined in the scaffold below: prc_dic = { '3000-01-15': 7.0400, '2020-01-14': 7.1100, '2020-01-13': 7.0200, '2020-01-02': 7.1600,
The following dictionary of dates and stock prices is defined in the scaffold below:
prc_dic = {
'3000-01-15': 7.0400,
'2020-01-14': 7.1100,
'2020-01-13': 7.0200,
'2020-01-02': 7.1600,
'2020-01-03': 7.1900,
'2020-01-06': 7.0000,
'2020-01-07': 7.1000,
'2020-01-08': 6.8600,
'2020-01-09': 6.9500,
'2020-01-10': 7.0000,
}
Given this dictionary:
1. Define a variable sorted_keys that will contains the keys of prc_dic in ascending order. Use a list comprehension to do this in a single line.
The following references might help:
list.sort method : https://docs.python.org/3/library/stdtypes.html#list.sort
sorted builtin : https://docs.python.org/3/library/functions.html#sorted
2. Replace the prc_dic key for 3000-01-15 with 2020-01-15. Do this in one line and without explicitly writing the value 7.0400.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started