Computer Science
What will the following code result in?
L1 = [1, 3, 5, 7, 9]
print (L1 == L1.reverse( ) )
print (L1)
Python
Python List Manipulation
29 Likes
Answer
False
[9, 7, 5, 3, 1]
Working
L1 is not equal to its reverse so L1 == L1.reverse( ) gives False but L1.reverse( ) reverses L1 in place so after that statement executes, L1 becomes [9, 7, 5, 3, 1].
Answered By
14 Likes
Related Questions
Given a list L1 = [3, 4.5, 12, 25.7, [2, 1, 0, 5], 88]
- Which list slice will return [12, 25.7, [2, 1, 0, 5]]?
- Which expression will return [2, 1, 0, 5]?
- Which list slice will return [[2, 1, 0, 5]]?
- Which list slice will return [4.5, 25.7, 88]?
Given a list L1 = [3, 4.5, 12, 25.7, [2, 1, 0, 5], 88], which function can change the list to:
- [3, 4.5, 12, 25.7, 88]
- [3, 4.5, 12, 25.7]
- [ [2, 1, 0, 5], 88]
Predict the output:
my_list= [ 'p', 'r', 'o', 'b', 'l' , 'e', 'm'] my_list[2:3] = [] print(my_list) my_list[2:5] = [] print(my_list)
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)