Posts Tuples (Python 3)
Post
Cancel

Tuples (Python 3)

  • URL : https://www.hackerrank.com/challenges/python-tuples/problem
  • Task
    • Given an integer, n, and n space-separated integers as input, create a tuple, t, of those n integers. Then compute and print the result of hash(t).
  • Note: hash() is one of the functions in the builtins module, so it need not be imported.

  • Input Format
    • The first line contains an integer, n, denoting the number of elements in the tuple.
    • The second line contains n space-separated integers describing the elements in tuple t.
  • Output Format
    • Print the result of hash(t).

문제풀이

  • 주어진 숫자를 tuple로 만들고, hash값을 출력하는것
  • hash()는 객체의 hash 값을 반환함.
1
2
3
4
if __name__ == '__main__':
    n = int(input())
    integer_list = map(int, input().split())
    print(hash(tuple(integer_list)))
1
2
3
4
5
 1
 2


3430020387561
This post is licensed under CC BY 4.0 by the author.