In PYTHON 3 please write function different that takes a two

In PYTHON 3 (please) write function different() that takes a two-dimensional table as input and returns the number of distinct entries in the table.

>>> t = [[1,0,1],[0,1,0]]
>>> different(t)
2
>>> t = [[32,12,52,63],[32,64,67,52],[64,64,17,34],[34,17,76,98]]
>>> different(t)
10

Solution

def different(l):
   arr = []
   count = 0
   for a in l:
       for b in a:
           if b not in arr:
               arr.append(b)
               count = count+1
   return count
a = different([[1,0,1],[0,1,0]])
print(a)
a = different([[32,12,52,63],[32,64,67,52],[64,64,17,34],[34,17,76,98]])
print(a)

In PYTHON 3 (please) write function different() that takes a two-dimensional table as input and returns the number of distinct entries in the table. >>>

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site