0

Here is the list [1, 9,8,8,7,6,1,6] I need an output which shows the non occurring numbers in this list in python.. Pls help 🙏

14th Sep 2020, 6:11 AM
Ganesh S
14 Answers
+ 7
Check out the .count() method available for Python lists. You can iterate through the list and call count using each element as the argument to the method. For non-reoccuring numbers, count returns 1. https://docs.python.org/3/tutorial/datastructures.html
14th Sep 2020, 6:17 AM
Hatsy Rei
Hatsy Rei - avatar
+ 5
I would make a master list [1,2,3,4,5,6,7,8,9,0] and knock off the numbers from this list.. This approach would work well with all languages 🙄
14th Sep 2020, 3:27 PM
Sanjay Kamath
Sanjay Kamath - avatar
+ 2
Show your attempt first
14th Sep 2020, 6:30 AM
AKSHAY🇮🇳
AKSHAY🇮🇳 - avatar
+ 1
Convert the list to a set(), because set has only unique numbers, then print the set as a list....that should work just fine!
14th Sep 2020, 1:30 PM
Adeola Adetilewa
Adeola Adetilewa - avatar
+ 1
I think you have an one another way to find that element are present or not in list I. e You can call all the elements from the list that can be whatever By using this-print(numbers.index(9) Out put will be-1 becouse index of number 9 is 1 That will be shown output And if u wan't to know 4 is present in list or not then Print(numbers.index(4). Then output is error Because that number is not in list
15th Sep 2020, 1:25 PM
AKASH KUMAR
AKASH KUMAR - avatar
0
from 1 to 10?
14th Sep 2020, 6:13 AM
Oma Falk
Oma Falk - avatar
0
Yeah
14th Sep 2020, 6:13 AM
Ganesh S
0
Sorry in that list
14th Sep 2020, 6:13 AM
Ganesh S
0
Which I gave
14th Sep 2020, 6:13 AM
Ganesh S
0
Which occurs only once
14th Sep 2020, 7:33 AM
Ganesh S
0
Both gives different result 1 don't take repeating number while 2 program just take repeating number once
15th Sep 2020, 11:36 AM
Shivam Rawal
0
I am not sure if you are looking for non-occurring numbers or non reoccuring numbers. For non reoccuring numbers, you can do as follows: list1 = [1, 9,8,8,7,6,1,6] listF = [X for X in list1 if list1.count(X) == 1] listF contains your answers [9,7] If you wanted to check non-occuring numbers from 0-10 against your list, you can do: list1 = [1, 9,8,8,7,6,1,6] list2 = [ *range(11) ] listF = [X for X in list2 if X not in list1]
16th Sep 2020, 5:16 AM
Ahmad Khan
0
list [1, 9,8,8,7,6,1,6] Result1 [1,9,8,7,6,] Result2 [9,7] Which one from the above you want as a result?
16th Sep 2020, 5:55 AM
Jhonie San Juan
Jhonie San Juan - avatar