LoginSignup
6
8

More than 1 year has passed since last update.

「pythonの辞書型」と「excelの関数」を比較してみた

Last updated at Posted at 2017-05-22

(参考) 以下おすすめです。たいへんわかりやすいです。

lookup関数

dic = {'apple':' りんご','orange':' みかん','lemon':' レモン'}
dicOut=dic['apple']
print('-----------------------------------------------------')
print(type('apple'),'apple')
print(type(dic)   ,dic)
print(type(dicOut),dicOut)
#<class 'str'> apple
#<class 'dict'> {'apple': ' りんご', 'orange': ' みかん', 'lemon': ' レモン'}
#<class 'str'>  りんご

sum関数

dic = {'apple':50,'orange':60,'lemon': 70}
list = dic.values()
gokei= sum(list)
print('-----------------------------------------------------')
print(type(list),list)
print(type(gokei),gokei)
#<class 'dict_values'> dict_values([50, 60, 70])
#<class 'int'> 180

(参考)

sumif関数

調査中

セルに名前を定義する(Nameプロパティ)

リスト1とリスト2から辞書型を作成

def list2dic(lst1,lst2):
    n=len(lst1)
    i=0
    dict={}
    while i<n:
       dict[lst1[i]]=lst2[i]
       i += 1
    else:
       return dict
lst1= ['apple' ,'orange', 'lemon']
lst2= ['りんご', 'みかん', 'レモン']
lst12=list2dic(lst1,lst2)
print(type(lst12),lst12)
#<class 'dict'> {'apple': 'りんご', 'orange': 'みかん', 'lemon': 'レモン'}

特定のセルまたはセル範囲を選択する

(参考)組み込みの dict 型に対する変更どうしても値のリストが必要な場合には、返された dict オブジェクトをキャストする

myDict = {'apple':50,'orange':60,'lemon': 70}
myList = myDict.values()
myCast = list(myList)
myGokei= sum(myList)
print('-----------------------------------------------------')
print(type(myList),myList)
print(type(myCast),myCast)
print(type(myGokei),myGokei)
# <class 'dict_values'> dict_values([50, 60, 70])
# <class 'list'> [50, 60, 70]
# <class 'int'> 180
6
8
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
8