2014年10月6日月曜日

開発環境

Practical Programming: An Introduction to Computer Science Using Python 3 (Pragmatic Programmers) (Paul Gries (著)、Jennifer Campbell (著)、Jason Montojo (著)、Lynn Beighley (編集)、Pragmatic Bookshelf)のChapter 11(Storing Data Using Other Collection Types)、11.8(Exercises) 5.を解いてみる。

11.8(Exercises) 5.

コード(BBEdit)

sample5.py

#!/usr/bin/env python3
#-*- coding: utf-8 -*-

def getParticle(d):
    t = 0
    result = ''
    flag = True
    
    for key, value in d.items():
        if flag:
            result = key
            t = value
            flag = False
        elif value < t:
            result = key
            t = value
        
    return result

if __name__== '__main__':
    print(getParticle({'neutron': 0.55, 'proton': 0.21, 'meson': 0.03,
                       'muon': 0.07, 'neutrino': 0.14}))

入出力結果(Terminal, IPython)

$ ./sample5.py
meson
$

0 コメント:

コメントを投稿