[Tutor] Finding the largest gap in tuple between two lists.

Avi Gross avigross at verizon.net
Sun Nov 18 08:11:36 EST 2018


Harry,

Your code may not have come through as intended as the formatting often
combined lines.

It may help to think about the question before giving deeper answers.

You have two places and two sets of goods with prices. You want the
intersection of those two to focus on what goods are in both. There are
various ways to do that ranging from using sets to creating an empty object
(such as a list or dictionary) then iterating over all items in group A and
adding only what is also IN group B.

You then want to maximize the difference in price for a particular item in
group A versus B. If you have the right data structures, that is a snap.

Suppose you made two dictionaries holding the keys in A and the keys in B
alongside values for each. You could iterate over the keys in either
dictionary and calculate A[key] = B[key] and if it is higher than the
previous high, replace the previous high while also saving the value of key.

Is that roughly what is needed? You buy one item with the maximum "profit"?

I can imagine having a fixed dollar amount to spend and a similar problem
where you can buy as many as you can afford of that item as a variant or
even a knapsack version where you might buy cheaper ones with any money
left, ...

If you post again, see if you can find a way to have the text formatted
properly as we have seen examples where Python programs get different
results, or fail completely, with changes in indentation.

-----Original Message-----
From: Tutor <tutor-bounces+avigross=verizon.net at python.org> On Behalf Of
Harry Oneill
Sent: Saturday, November 17, 2018 8:55 PM
To: tutor at python.org
Subject: [Tutor] Finding the largest gap in tuple between two lists.

Hello there everyone i hope you are all doing fantastic.

Im currently working on a little program that is designed to do a basic
function to help me to trade efficiently within the game Star Citizen:

#1 take two inputs ( location and destination )
#2 Find what product is best to buy at location to sell at destination
#3 Print the results

currently i have figured out how to get python to take the two inputs and
provide me with the lowest buy price and highest sell price.

However the information i want to produce is what has the largest profit
margin possible between the two locations so i need to compare what items
are available in both locations and then see what one has the largest price
difference then display that items name.

Below is  the code i have currently made for this.


Current_Location = input("Where are you currently located? :").lower()
Current_Destination = input("Where are you planning to travel? :").lower()

def Find_Lowest_Buy_Olisar():
    print("Finding lowest buy price for OLISAR...")
    print(*Sort_Buying_Olisar[:1], sep='\n') def Find_Highest_Sell_Olisar():
    print("Finding highest sell price for OLISAR...")
    print(*Sort_Selling_Olisar[:1], sep='\n') def Find_Lowest_Buy_Levski():
    print("Finding lowest buy price for LEVSKI...")
    print(*Sort_Buying_Levski[:1], sep='\n') def Find_Highest_Sell_Levski():
    print("Finding highest sell price for LEVSKI...")
    print(*Sort_Selling_Levski[:1], sep='\n')

Buying_Olisar = [('Medical Supply', 17.01), ('Waste', 0.005),]
Sort_Buying_Olisar = sorted_by_second = sorted(Buying_Olisar, key=lambda
tup: tup[1])

Selling_Olisar = [('Agricium', 25.60), ('Aluminum', 1.25), ('Beryl', 4.26),
('Chlorine', 1.57), ('Corundum', 2.53), ('Diamond', 6.90), ('Distilled
Spirits', 4.95), ('Fluorine', 2.80), ('Gold', 6.07), ('Hydrogen', 1.02),
('Iodine', 0.41), ('Laranite', 28.91), ('Processed Food', 1.39), ('Quartz',
1.44), ('Scrap', 1.67), ('Stims', 3.40), ('Titanium', 8.27), ('Tungsten',
3.90),] Sort_Selling_Olisar = sorted(Selling_Olisar, key=lambda
tup:(-tup[1], tup[0]))

Buying_Levski = [('Agricultural Supply', 1.11), ('Aluminum', 1.20),
('Hydrogen', 0.98), ('Iodine', 0.38), ('Quartz', 1.37), ('Waste', 0.005),]
Sort_Buying_Levski = sorted_by_second = sorted(Buying_Levski, key=lambda
tup: tup[1])

Selling_Levski = [('Agricium', 25.60), ('Altruciatoxine', 11.63), ('Beryl',
4.25), ('Chlorine', 1.56), ('Corundum', 2.53), ('Diamond', 6.07),
('Distilled Spirits', 4.95), ('Fluorine', 2.80), ('Gold', 6.07),
('Laranite', 28.25), ('Medical Supply', 18.00), ('Processed Food', 1.38),
('Scrap', 1.68), ('Stims', 3.40), ('Titanium', 8.27), ('Tungsten', 3.90),
('Widdow', 24.00),] Sort_Selling_Levski = sorted(Selling_Levski, key=lambda
tup:(-tup[1], tup[0]))


if Current_Location == "olisar":
    Find_Lowest_Buy_Olisar()
elif Current_Location == "levski":
    Find_Lowest_Buy_Levski()
else:
    print("Unknown location please try again.")

if Current_Destination == "olisar":
    Find_Highest_Sell_Olisar()
elif Current_Destination == "levski":
    Find_Highest_Sell_Levski()
else:
    print("Unknown location please try again.")


Any input would be hugely appreciated.

Kind regards,

Harry O'Neill
_______________________________________________
Tutor maillist  -  Tutor at python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor



More information about the Tutor mailing list