We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Your approach would work for integers entered on separate lines like this:
2
1
2
But the input is expecting the size to be the first line and space separated values on the second line.
You can use the split() method to create a list out of space separated input values and then convert the list to integer values using the built-in map() function to create a map object. Then you convert that map object to the desired structure so that would be a tuple with the tuple() method in this case.
Here's the modified code:
n = int(input())
temp_l = map(int, input().split())
temp_tup = tuple(temp_l)
print(hash(temp_tup))
Here is your code modified:
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
An unexpected error occurred. Please try reloading the page. If problem persists, please contact support@hackerrank.com
Tuples
You are viewing a single comment's thread. Return to all comments →
Your approach would work for integers entered on separate lines like this: 2 1 2
But the input is expecting the size to be the first line and space separated values on the second line. You can use the split() method to create a list out of space separated input values and then convert the list to integer values using the built-in map() function to create a map object. Then you convert that map object to the desired structure so that would be a tuple with the tuple() method in this case.
Here's the modified code:
n = int(input())
temp_l = map(int, input().split())
temp_tup = tuple(temp_l)
print(hash(temp_tup))
Here is your code modified: