diff --git a/labs03/task01.py b/labs03/task01.py index 8045eb8..3865340 100644 --- a/labs03/task01.py +++ b/labs03/task01.py @@ -1,3 +1,8 @@ #lab03 task01 #Returns mutable type names -[t for t, oldid, newid in map( lambda (t, obj, objid): (t, id(obj*1), objid), map(lambda x : (type(x), x, id(x)), [[], '', 3.141592]) ) if oldid == newid] \ No newline at end of file +[t for t, oldid, newid in map( lambda (t, obj, objid): (t, id(obj*1), objid), map(lambda x : (type(x), x, id(x)), [[], '', 3.141592]) ) if oldid == newid] + +for type_name, type_mutable in map( lambda t: (type(t), id(t)==id(t*1)), [[], '', 3.141592] ): + print("%s is %s" % (str(type_name), 'mutable' if type_mutable else 'immutable') ) + + diff --git a/labs03/task02.py b/labs03/task02.py index efcf4dc..e43b6ba 100644 --- a/labs03/task02.py +++ b/labs03/task02.py @@ -1,10 +1,7 @@ # lab03, task02 def fibN(n): - prev, current = 0, 1 + prev, current = 1, 1 for n in range(n): yield prev prev, current = current, prev + current - -for x in fibN(10): - print(x) \ No newline at end of file diff --git a/labs03/task03.py b/labs03/task03.py new file mode 100644 index 0000000..a24fe92 --- /dev/null +++ b/labs03/task03.py @@ -0,0 +1,15 @@ +# -*- coding: utf-8 -*- +import requests, json + +# try: +# print('EUR:PLN %3.4f' % (requests.get('https://api.fixer.io/latest').json()['rates']['PLN'])) +# except: +# print("Something went wrong. Couldn't display EUR:PLN exchange rate.") +# +# Niestety nie znalazłem w pakiecie json dla pythona 2.7 operacji zwracającej wspomniany w treści zadania +# 'obiekt typu JSON' -czytanie streamu zamienia dane na zwykłe pythonowe słowniki. Nie wnosi to więc wartości dodanej +# do powyższego kodu, który w metodzie.json() zwraca obiekt typu dict, podobnie jak przyjmująca łańcuch znaków +# funkcja json.loads. +print(json.loads(requests.get('https://api.fixer.io/latest').text))['rates']['PLN'] +# assert type(json.loads(requests.get('https://api.fixer.io/latest').text)) == type(dict()) +# diff --git a/labs03/task04.py b/labs03/task04.py new file mode 100644 index 0000000..56aef98 --- /dev/null +++ b/labs03/task04.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +from weather import Weather +import datetime + +weather = Weather() +loc = weather.lookup_by_location('Poznan') +print('Informacja o aktualnej pogodzie: %s' % loc.condition().text()) + +def ftoc(f): + return (f-32.0)*5.0/9.0 + +def date_to_pl_weekday(date_string): + """ + input: string of form '10 Dec 2017' + output: weekday in polish language + """ + idx = datetime.datetime.strptime(date_string, '%d %b %Y').weekday() + return [u'poniedziałek', u'wtorek', u'środa', u'czwartek', u'piątek', u'sobota', u'niedziela'][idx] + +min_day = min(loc.forecast(), key = lambda f: f.low()) +print(u'Najbliższy najzimniejszy dzień to %s. Będzie %s\u00B0C. ' % (date_to_pl_weekday(min_day.date()), ftoc(int(min_day.low())))) + diff --git a/labs03/task05.py b/labs03/task05.py new file mode 100644 index 0000000..486c073 --- /dev/null +++ b/labs03/task05.py @@ -0,0 +1,18 @@ +import glob, os + +# print(glob.glob('./scores/model.iter[0-9][0-9][0-9][0-9][0-9][0-9][0-9].npz.bleu')) + + + +def extract_BLEU_score(fn): + ''' + :param fn - path to file with : + :return: + ''' + with open(fn, 'r') as fd: + line = fd.readline() + return (os.path.abspath(fn), float(line[6:line.index(',')])) + +print max([ t for t in map(extract_BLEU_score, glob.iglob('./scores/model.iter[0-9][0-9][0-9][0-9][0-9]*.npz.bleu'))], key = lambda tpl: tpl[1])[0] + +