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.
In google colab, this code runs excatly as expected but I don't know how do I take the integer inputs given in single line separated by 'space'. Please tell me how do I take such inputs given in single line.
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
Join us
Create a HackerRank account
Be part of a 26 million-strong community of developers
Please signup or login in order to view this challenge
Tuples
You are viewing a single comment's thread. Return to all comments →
In google colab, this code runs excatly as expected but I don't know how do I take the integer inputs given in single line separated by 'space'. Please tell me how do I take such inputs given in single line.
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: