arturParchem

[P] Najczęstsza

Oct 3rd, 2022
782
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.43 KB | None | 0 0
  1. t=[5,2,1,5,2,2,1,2,1]
  2. t.sort()
  3. def najczczestszy(A):
  4.     aktualny=A[0]
  5.     ile=1
  6.     najczesy=A[0]
  7.     ile_najcz=1
  8.     for i in range(1,len(A)-1):
  9.         if A[i]==A[i-1]:
  10.             ile+=1
  11.             if ile>ile_najcz:
  12.                 ile_najcz=ile
  13.                 najczesy=aktualny
  14.         else:
  15.             aktualny=A[i]
  16.             ile=1
  17.     return str(najczesy)+" występuje "+str(ile_najcz)
  18. print(najczczestszy(t))
Advertisement
Add Comment
Please, Sign In to add comment