Python program to put positive numbers at even indexes (0, // 2,.) and



Download 9,43 Mb.
bet3/3
Sana13.07.2022
Hajmi9,43 Mb.
#793218
1   2   3
Bog'liq
Abdullayeva Dildora Xurshed Qizi 18-04 g 3 kurs

# Driver code
if __name__ == '__main__':
 
print("First Test")
arr1 = [4, 5, 6, 7, 8, 4, 4]
size = len(arr1)
k = 3
moreThanNdK(arr1, size, k)
 
print("Second Test")
arr2 = [4, 2, 2, 7]
size = len(arr2)
k = 3
moreThanNdK(arr2, size, k)
 
print("Third Test")
arr3 = [2, 7, 2]
size = len(arr3)
k = 2
moreThanNdK(arr3, size, k)
 
print("Fourth Test")
arr4 = [2, 3, 3, 2]
size = len(arr4)
k = 3
moreThanNdK(arr4, size, k)
 
# This code is contributed by mohit kumar 29
# Python3 code to find elements whose
# frequency yis more than n/k
def morethanNbyK(arr, n, k) :
x = n // k

# unordered_map initialization
freq = {}

for i in range(n) :
if arr[i] in freq :
freq[arr[i]] += 1
else :
freq[arr[i]] = 1

# Traversing the map
for i in freq :

# Checking if value of a key-value pair
# is greater than x (where x=n/k)
if (freq[i] > x) :

# Print the key of whose value
# is greater than x
print(i)

# Driver code
arr = [ 1, 1, 2, 2, 3, 5, 4, 2, 2, 3, 1, 1, 1 ]
n = len(arr)
k = 4

morethanNbyK(arr, n, k)

# This code is contributed by mohit kumar 29

2 usul: O'rnatilgan Python funktsiyalaridan foydalanish:




Counter () funktsiyasi yordamida har bir elementning chastotalarini hisoblang.
Chastotalar qatorini kesib o'ting va n / k martadan ko'proq sodir bo'lgan barcha elementlarni chop eting.
Quyida amalga oshirish:

Python3 implementation
from collections import Counter
 
# Function to find the number of array
# elements with frequency more than n/k times
def printElements(arr, n, k):
 
# Calculating n/k
x = n//k
 
# Counting frequency of every
# element using Counter
mp = Counter(arr)

# Traverse the map and print all
# the elements with occurrence
# more than n/k times
for it in mp:
if mp[it] > x:
print(it)
 
 
# Driver code
arr = [1, 1, 2, 2, 3, 5, 4, 2, 2, 3, 1, 1, 1]
n = len(arr)
k = 4
 
printElements(arr, n, k)
 
# This code is contributed by vikkycirus
Download 9,43 Mb.

Do'stlaringiz bilan baham:
1   2   3




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish