jeudi 15 décembre 2022

How to sort the websites by their popularity?

Im using the script currently and i cant seem to find out a way to sort the Websites by their popularity, im a beginner.

import random

# création d'un dictionnaire Hypertexte
Hypertext = {}
# création d'un dictionnaire pour le nombre de visite
Walk_Number = {}
# une variable pour le nombre total de visite
Total_Walk = 0
#liste des sites web
Websites = ["A","B","C","D","E","F"]
# les liens hypertextes
#  le dictionnaire possède des clés ( nom des sites)
# Qui contiennent des listes (liens hypertextes)
Hypertext["A"] = ["B","C","E"]
Hypertext["B"] = ["F"]
Hypertext["C"] = ["A","E"]
Hypertext["D"] = ["B","C"]
Hypertext["E"] = ["A","B","C","D","F"]
Hypertext["F"] = ["E"]
print(Hypertext)
# On initialise à 0.0 les visites des sites 
Walk_Number["A"] = 0.0
Walk_Number["B"] = 0.0
Walk_Number["C"] = 0.0
Walk_Number["D"] = 0.0
Walk_Number["E"] = 0.0
Walk_Number["F"] = 0.0

i = 0
while i < 1000:
    x = random.choice(Websites)
    while random.random() < 0.85:
        Walk_Number[x] = Walk_Number[x] + 1
        Total_Walk = Total_Walk + 1     
        x = random.choice(Hypertext[x])
    i = i + 1
print (Walk_Number)
print(Total_Walk)

I tried using the sort() function but i cant seem to find a way to sort it into the script




Aucun commentaire:

Enregistrer un commentaire