Answer to Question #225788 in Python for Siva

Question #225788



First and Last Elements of List

You are given an integer

N as input. Write a program to read N integers and print a list containing the first and last two inputs.Input

The first line of input is an integer

N. The next N lines each contains an integer.Explanation

In the given example, we are given

6 numbers 1, 2, 3, 4, 5, 6 as input.The list should contain first two integers

1, 2 and last two integers 5, 6 So, the output should be [1, 2, 5, 6].

Sample Input 1

6

1

2

3

4

5

6

Sample Output 1

[1, 2, 5, 6]

Sample Input 2

5

1

11

13

21

19

Sample Output 2

[1, 11, 21, 19]



1
Expert's answer
2021-08-13T01:47:49-0400
n = int(input())
list = []

for i in range(n):
    list.append(input())

del list[2:-2]
print(list)

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS