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 🙏
14 Respostas
+ 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
+ 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 🙄
+ 2
Show your attempt first
+ 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!
+ 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
0
from 1 to 10?
0
Yeah
0
Sorry in that list
0
Which I gave
0
Which occurs only once
0
Both gives different result 1 don't take repeating number while 2 program just take repeating number once
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]
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?