Computer Science
Write equivalent list comprehension for the following code :
target1 = []
for number in source:
if number & 1:
target1.append(number)
Python
Linear Lists
3 Likes
Answer
target1 = [number for number in source if number & 1]
Answered By
2 Likes
Related Questions
Modify your previous code so that SqLst stores the doubled numbers in ascending order.
Consider a list ML = [1, 4, 9, 16, 25, 36, 49, 64, 81, 100]. Write code using a list comprehension that takes the list ML and makes a new list that has only the even elements of this list in it.
Write equivalent for loop for the following list comprehension :
gen = (i/2 for i in [0, 9, 21, 32]) print(gen)
Predict the output of following code if the input is :
(i) 12, 3, 4, 5, 7, 12, 8, 23, 12
(ii) 8, 9, 2, 3, 7, 8
Code :
s = eval(input("Enter a list : ")) n = len(s) t = s[1:n-1] print(s[0] == s[n-1] and t.count(s[0]) == 0)