- 3
Why not three?
What is the result of this code? nums = {1, 2, 3, 4, 5, 6} nums = {0, 1, 2, 3} & nums nums = filter(lambda x: x > 1, nums) print(len(list(nums))) --- First --- you have all the numbers. Then you have only the numbers in common. Then you're filtering those numbers, with the x > 1 rule. The answer is a single number. Why was the third number not included? It was also True.
16 odpowiedzi
+ 5
nums = {1, 2, 3, 4, 5, 6}
nums = {0, 1, 2, 3} & nums # This is an intersection of the 2 lists leaving only the common elements
print(nums) # {1, 2, 3}
nums = list(filter(lambda x: x > 1, nums)) # filter out any values not greater than 1
print(nums) # {2, 3}
print(len(nums)) # print length of nums - 2
+ 5
2
+ 4
Youre ultimately getting the length of the list ...
numbers in common are 1, 2, 3
then greater than 1 is just 2 and 3
then length is 2
0
I understand now, thank you.
0
2
0
2
0
nums = {1, 2, 3, 4, 5, 6}
nums = {0, 1, 2, 3} | nums
nums = filter(lambda x: x > 2, nums)
print((list(nums)))
>>> [3, 4, 5, 6]
# The Solution is - This Mark "|" is show the whole numbers without their couple. x > 2 It means that -> (hey dear filter) -> please take out the whole numbers which are higher than 2
0
nums = {1, 2, 3, 4, 5, 6}
nums = {0, 1, 2, 3} & nums
# (& is use for find the common elements in tuple,set or list)
nums ={0, 1, 2, 3} & {1, 2, 3, 4, 5, 6}
# so we will get the value of nums are as
nums={1, 2, 3}
# lambda function will check every element in nums if they are greater than 1 and will again store then in num
nums = filter(lambda x: x > 1, nums)
#so we will get the value of num as
num={2, 3}
#hence the length of the num is 2 now . so it will print 2
print(len(list(nums)))
0
2
0
2
- 1
What is the result of this code?
nums = {1, 2, 3, 4, 5, 6}
nums = {0, 1, 2, 3} & nums
nums = filter(lambda x: x > 1, nums)
print(len(list(nums)))
2
- 1
2
- 1
question : What is the result of this code?
nums = {1, 2, 3, 4, 5, 6}
nums = {0, 1, 2, 3} & nums
nums = filter(lambda x: x > 1, nums)
print(len(list(nums)))
output : 2
- 1
2 is the answer
- 1
Answer is 2
- 1
2