अधिकतम कीमत वाला स्टॉक ढूँढना
एक और उपयोगी list मेथड .index() है, जो दिए गए एलिमेंट का इंडेक्स लौटाता है। उदाहरण के लिए, x में 2 का इंडेक्स पाने के लिए आप यह लिखेंगे:
x = [1, 2, 3, 4]
x.index(2)
1
इसके परिणाम का उपयोग आप किसी दूसरी list को subset करने के लिए कर सकते हैं, जैसा आप इस अभ्यास में करेंगे.
आपके workspace में prices और names नाम की lists उपलब्ध हैं.
यह अभ्यास पाठ्यक्रम का हिस्सा है
Finance के लिए Python परिचय
अभ्यास निर्देश
- list
pricesमेंmax_priceका इंडेक्स पहचानें. - इसी इंडेक्स को
nameslist पर लगाकर उस कंपनी की पहचान करें जिसकी stock price अधिकतम है.
इंटरैक्टिव व्यावहारिक अभ्यास
इस अभ्यास को इस नमूना कोड को पूरा करके आज़माएँ।
# Do not modify this
max_price = max(prices)
# Identify index of max price
max_index = prices.____(____)
# Identify the name of the company with max price
max_stock_name = names[____]
# Fill in the blanks
print('The largest stock price is associated with ' + max_stock_name + ' and is $' + str(max_price) + '.')