- 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.

1st Sep 2017, 5:17 PM
Samantha Jordan
Samantha Jordan - avatar
16 Respuestas
+ 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
1st Sep 2017, 5:38 PM
ChaoticDawg
ChaoticDawg - avatar
+ 5
2
14th Sep 2018, 10:34 AM
Pallavi Gangadhar Savkar
+ 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
1st Sep 2017, 5:33 PM
Joni Jimenez
Joni Jimenez - avatar
0
I understand now, thank you.
1st Sep 2017, 6:38 PM
Samantha Jordan
Samantha Jordan - avatar
0
2
11th Jan 2020, 7:27 AM
Babeetha Muruganantham
Babeetha Muruganantham - avatar
0
2
28th Jan 2020, 6:43 AM
GOVINDHARAJPERUMAL R
GOVINDHARAJPERUMAL R - avatar
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
16th Feb 2020, 4:09 PM
Hakuna Matata
Hakuna Matata - avatar
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)))
6th Mar 2021, 8:46 AM
Bishwanath Kumar
Bishwanath Kumar - avatar
0
2
9th May 2022, 7:51 PM
Abdoullah Diallo
0
2
6th Nov 2023, 1:16 PM
Harish S CSA CBE
Harish S CSA CBE - avatar
- 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
28th Apr 2020, 7:42 AM
makhan Kumbhkar
makhan Kumbhkar - avatar
- 1
2
13th May 2020, 5:35 AM
Kiran Govardhan Khendake
Kiran Govardhan Khendake - avatar
- 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
28th May 2021, 5:51 PM
Madhavareddy
Madhavareddy - avatar
- 1
2 is the answer
24th Jul 2021, 6:14 AM
Judson Leo
Judson Leo - avatar
- 1
Answer is 2
3rd Dec 2021, 2:31 PM
Thuwayba Ahmed
Thuwayba Ahmed - avatar
- 1
2
1st Feb 2022, 9:43 AM
KESHAV KONDABALA
KESHAV KONDABALA - avatar