#!/usr/bin/env python3 #title :8-4.py #description :Opdracht 8.4 - File & dict #author :Marcel Haazen #email :marcel@haazen.xyz #date :28-10-2019 - 13:20 #version :0.1 #usage :python3 8-4.py #notes : #python_version :3.7.3 #============================================================================== def ticker(): filename = 'tickers.txt' tickers = {} with open(filename) as fh: for line in fh: company, ticker = line.strip().split(':', 1) tickers[company] = ticker.strip() return tickers try: comp = str(input("Enter Company name: ")).upper() print((ticker())[comp]) except KeyError as identifier: print("Dit bedrijf in onbekend.") try: tick = comp = str(input("Enter Ticker symbol: ")).upper() print([key for key in ticker().items() if key[1] == tick][0][0]) except StopIteration as identifier: print("Dit bedrijf in onbekend.")