Computer Science
Find the error in the following list comprehension :
["good" if i < 3: else: "better" for i in range(6)]
Linear Lists
2 Likes
Answer
The code contains a syntax error due to the placement of the colon (:). There should not be colon in list comprehension.
Answered By
1 Like
Related Questions
Find the error. Consider the following code and predict the error(s):
y for y in range(100) if y % 2 == 0 and if y % 5 == 0
Find the error. Consider the following code and predict the error(s):
(y for y in range(100) if y % 2 == 0 and if y % 5 == 0)
Suggest corrections for the errors in both the previous questions.
Write a program that uses a function called findinlist() to check for the position of the first occurrence of v in the list passed as parameter (lst) or -1 if not found. The header for the function is given below :
def find_in_list(lst, v): """ lst - a list v - a value that may or may not be in the list """