[Python] How to read an array of integers from single line of input in python3

Discussão em 'Python' iniciado por Stack, Abril 18, 2025.

  1. Stack

    Stack Membro Participativo

    I want to read an array of integers from single line of input in python3. For example: Read this array to a variable/list

    1 3 5 7 9

    What I have tried


    1. arr = input.split(' ') But this does not convert them to integers. It creates array of strings


    2. arr = input.split(' ')

      for i,val in enumerate(arr): arr = int(val)



    2nd one is working for me. But I am looking for an elegant(Single line) solution.

    Continue reading...

Compartilhe esta Página