Question
Hi, I have the following code: def get_price(str): items = str.split(':') return float(items[1]) def get_month(str): items = str.split('-') return int(items[0]) def get_day(str): items = str.split('-')
Hi, I have the following code:
def get_price(str): items = str.split(':') return float(items[1])
def get_month(str): items = str.split('-') return int(items[0])
def get_day(str): items = str.split('-') return int(items[1])
def get_year(str): items = str.split(':') date_items = items[0].split('-') return int(date_items[2])
def main(): gas_file = open('gas prices.txt', 'r') gas_list = gas_file.readlines() gas_list.sort() print (sorted (gas_list)) main()
I am trying to get it to sort the prices of a "gas list" file by price lowest to highest. Right now its sorting the dates intead. Can you please help me with that? The format of the dates is 04-05-1993:1.068
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