How to find length of dictionary values

后端 未结 6 1702
忘了有多久
忘了有多久 2020-12-13 18:24

I am pretty new to all of this so this might be a noobie question.. but I am looking to find length of dictionary values... but I do not know how this can be done.

S

6条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-13 18:49

    Let dictionary be :
    dict={key:['value1','value2']}

    If you know the key :
    print(len(dict[key]))

    else :
    val=[len(i) for i in dict.values()]
    print(val[0])
    # for printing length of 1st key value or length of values in keys if all keys have same amount of values.

提交回复
热议问题