[Solved] what is arr = [int(arr_temp) for arr_temp in input().strip().split(‘ ‘)] in python


You may want to look into python’s list comprehension.

arr = [int(arr_temp) for arr_temp in input().strip().split(' ')]

Let me answer this with an example, suppose you input :

   1 3 4 29 12 -2 0
  • the input function reads this as a string
  • The strip function eliminates whitespace from both ends of the string,
  • The split function splits the string into smaller strings with a delimiter: (that is a literal space)
  • In the list comprehension you can read it as :

    for arr_temp in input().strip().split(' ') :
        int(arr_temp)
    

    We get a list of integers stored in the variable arr (arr = [1, 3, 4, 29, 12, -2, 0]). This is not an actual replacement code for the list comprehension but it might give you a better understanding of what it is trying to do.

Extra note : Apart from lists, Python also has comprehension expressions for sets, dictionaries and generators.

solved what is arr = [int(arr_temp) for arr_temp in input().strip().split(‘ ‘)] in python