list input in python

Description

Python Program to get list size n and n elements of list, then print the elements.
Input:
5
5 7 9 3 1
Output:
5 7 9 3 1

Solution

l=list(map(int,input("Enter array elements:").split(" ")))
for i in l:
    print(i)

Explanation

To get list of numbers seprated by space, use split(" ") method. Split() method splits the numbers as seprate elements. 
By default this methods are considered as string, since input() method returs string.

Use map() function to convert all elements as integer and store it in list.
Ramesh P Natarajan

Author - Ramesh P Natarajan

Learner, Professor, Technology Trainer, Software Developer and Content Marketer, very much passionate in the field of Software Application Development, Machine Learning and Search Engine Optimization.

Write to: admin@decodeschool.com





Interesting Pattern Programs: for more Patterns

Input:
5
Output:
*
**
***
****
*****
****
***
**
*Solution
Input:
5
Output:
    *
   ***
  *****
 *******
*********
 *******
  *****
   ***
    *Solution
Input:
5
Output:
*        *
**      **
***    ***
****  ****
**********Solution
Input:
5
Output:
*       *
**     **
***   ***
**** ****
*********Solution
Input:
5
Output:
*       *
**     **
***   ***
**** ****
*********
**** ****
***   ***
**     **
*       *Solution
Input:
5
Output:
*********
 *******
  *****
   ***
    *
   ***
  *****
 *******
*********Solution