• + 1 comment

    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.

    n = int(input())
    temp_l = []
        
    for _ in range(n):
      num = int(input())
      temp_l.append(num)
    
    temp_tup = tuple(temp_l)  
    print(hash(temp_tup))
    
    • + 0 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: