Skip to content

Added 41_python.py #103

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions Python/41_python.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@

# Created a dictionary called stocks

stocks = {
#Ticker, #Stock Rates

'GOOG': 520.54,
'FB': 76.45,
'YHOO': 39.28,
'AMZN': 306.21,
'AAPL': 99.76
}

# If we put stocks.keys() first and then stocks.values(), it would be sorted in alphabatical order
# This zip the dictionary in a list and in different tuples.
# zip(stocks.values(), stocks.keys())

print(min(zip(stocks.values(), stocks.keys()))
# Will print the minimum stock rate with its ticker.

print(min(zip(stocks.values(), stocks.keys()))
# Will print the maximum stock rate with its ticker.

print(sorted(zip(stocks.values(), stocks.keys()))
# Will print the stocks in ascending order according to the stocks rates.


#But if we put stocks.key() first then it will print stocks from A - Z according to the name of tickers
print(sorted(zip(stocks.keys()), stocks.values()))