취미생활/CheckIO

[checkIO]Element 08.Best Stock

우주먼지의하루 2020. 3. 14. 09:19
728x90

You are given the current stock prices. You have to find out which stocks cost more.

 

Input: The dictionary where the market identifier code is a key and the value is a stock price.

Output: The market identifier code (ticker symbol) as a string.

 

Example:

best_stock({"CAC": 10.0, "ATX": 390.2, "WIG": 1.2}) == "ATX"

best_stock({"CAC": 91.1, "ATX": 1.01, "TASI": 120.9}) == "TASI"

 

* 딕셔너리 형태로 값 비교해서 제일 큰 숫자 index 출력하기.

 

- 풀이

 

def best_stock(a):
    val = max(a.values())
    
    for key,value in a.items():
        if val == value:
            return key

 

 

반응형

'취미생활 > CheckIO' 카테고리의 다른 글

[checkIO]Element 10.Right to Left  (2) 2020.03.21
[checkIO]Element 09.Correct Sentence  (0) 2020.03.18
[checkIO]Element 07.Even the Last  (0) 2020.03.07
[checkIO]Element 06.Fizz Buzz  (0) 2020.03.03
[checkIO]Element 05.Secret Message  (0) 2020.03.01