Computer Science

Predict the output:

List1 = [13, 18, 11, 16, 13, 18, 13]
print(List1.index(18)) 
print(List1.count(18)) 
List1.append(List1.count(13))
print(List1)

Python

Python List Manipulation

31 Likes

Answer

1
2
[13, 18, 11, 16, 13, 18, 13, 3]

Working

List1.index(18) gives the first index of element 18 in List1 which in this case is 1. List1.count(18) returns how many times 18 appears in List1 which in this case is 2. List1.count(13) returns 3 as 13 appears 3 times in List1. List1.append(List1.count(13)) add this 3 to the end of List1 so it becomes [13, 18, 11, 16, 13, 18, 13, 3].

Answered By

15 Likes


Related Questions