Python#hash()

hashは簡単にいいますと、Hash値は固定な整数です。どんな与えでもこれしかないHash値があり、そしてPythonはhash()という関数があります。

https://stackoverflow.com/questions/17585730/what-does-hash-do-in-python

https://en.wikipedia.org/wiki/Hash_function

以下のCodeはInput()から一列の数値がもらい>整数の配列に変換>tupleに変換>hash()関数使ってhash値をもらうのような感じです。

if __name__ == ‘__main__’:
    n = int(input())
    l=[int (x) for x in input().split()]
    print(hash(tuple(l)))
   

シェアする

  • このエントリーをはてなブックマークに追加

フォローする