Python - gazpacho - Working with Data: Data Manipulation - function, argument
Head First Python: A Learner’s Guide to the Fundamentals of Python Programming, A Brain-Friendly Guide、 Paul Barry(著)、 O’Reilly Mediaの Chapter 10. (Working with Data: Data Manipulation)、EXERCISE(469/682)の解答を求めてみる。
Jupyter(コード、入出力結果)
webapp/WorldRecords.ipynb
def event_lookup(event):
conversions = {
'Free': 'freestyle',
'Back': 'backstroke',
'Breast': 'breaststroke',
'Fly': 'butterfly',
'IM': 'individual medley',
}
*_, distance, stroke = event.removesuffix('.txt').split('-')
return f'{distance} {conversions[stroke]}'
event_lookup('Mike-15-100m-Fly.txt')
'100m butterfly'