Find the element that appears once in a array | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Find the element that appears once in a array

Can you please help me to sole above problem in python3

25th Jan 2020, 6:48 PM
Pavan Sirsat
Pavan Sirsat - avatar
8 Answers
0
well...atleast you've had a go, this is how I would do it:- mylist = [1, 2, 3, 4, 5, 6, 7, 1, 2, 3, 4, 5, 6] print(*[x for x in mylist if mylist.count(x) == 1], sep=', ')
25th Jan 2020, 7:20 PM
rodwynnejones
rodwynnejones - avatar
+ 3
What did u already try? I see no code
25th Jan 2020, 6:56 PM
Oma Falk
Oma Falk - avatar
+ 2
Hurry up yourself. We also help doing homework if your part is big enough.
25th Jan 2020, 6:59 PM
Oma Falk
Oma Falk - avatar
+ 1
Use list comprehension and lists' "count" method.
25th Jan 2020, 7:03 PM
rodwynnejones
rodwynnejones - avatar
+ 1
rodwynnejones ....pleaaaaase discipline
25th Jan 2020, 7:25 PM
Oma Falk
Oma Falk - avatar
0
I didn't
25th Jan 2020, 6:57 PM
Pavan Sirsat
Pavan Sirsat - avatar
0
def bubblesort(arr): n=len(arr) for i in range(n): if arr[0] != arr[1] and arr[0] != arr[2]and arr[0] != arr[3]and arr[0] != arr[4]and arr[0] != arr[5]and arr[0] != arr[6]and arr[0] != arr[7]and arr[0] != arr[8]and arr[0] != arr[9]and arr[0] != arr[10]and arr[0] != arr[11]and arr[0] != arr[12]and arr[0] != arr[13]and arr[0] != arr[14]and arr[0] != arr[15]and arr[0] != arr[16]and arr[0] != arr[13]and arr[0] != arr[18]and arr[0] != arr[19]: print(arr[0]) arr = [-20, 20, -10, 20, 0, 4, 8, -20, 10, -10, 8, 6, 15, 9, 18, 35, 40, -30, -90, 99] bubblesort(arr) here i try one comparison of arr[0] .how can i compare every element of array with other element using for loop i.e. Find the elements from an array A, that appears only once. E.g. N = 20 A = {-20, 20, -10, 20, 0, 4, 8, -20, 10, -10, 8, 6, 15, 9, 18, 35, 40, -30, -90, 99} Array elements which appeared only once are (order of element should not change). = { 0, 4, 10, 6, 15, 9, 18, 35, 40, -30, -90, 99 }
25th Jan 2020, 7:12 PM
Pavan Sirsat
Pavan Sirsat - avatar
0
thanks buddy
25th Jan 2020, 7:24 PM
Pavan Sirsat
Pavan Sirsat - avatar