-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLength_Charcount_5.0.py
More file actions
75 lines (59 loc) · 1.51 KB
/
Length_Charcount_5.0.py
File metadata and controls
75 lines (59 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#Made by MScript 2024
#geeft lengte van alle woorden in een string
#import ascii uppercase alphabet
from string import ascii_uppercase as alc
#call global vars
xDict = {"key" : "value"}
#function Start
def start():
text = input("geef tekst in:")
print("1: Alfabetisch, 2: aantal hoog naar laag, 3: beide")
opt = input("Welke volgorde?")
#remove all non-letters from string
onlyLetters = "".join(filter(str.isalpha, text))
#get string length
strLength = len(text)
onlyLettersLength = len(onlyLetters)
print("\n")
print("totale lengte is:", strLength)
print("\n")
print("aantal letters is:", onlyLettersLength)
print("\n")
#covert lowercase to uppercase
onlyCaps = onlyLetters.upper()
#call next function
if opt == "1":
alphaOrder(onlyCaps)
elif opt == "2":
highToLow(onlyCaps, xDict)
elif opt == "3":
alphaOrder(onlyCaps)
print("\n")
highToLow(onlyCaps, xDict)
else:
print("onbekende optie gekozen")
#volgende function geeft char count
def alphaOrder(onlyCaps):
for x in alc:
numLetter = onlyCaps.count(x)
print(x, ":", numLetter)
#fill dict with letters and their value
def highToLow(onlyCaps, xDict):
for x in alc:
numLetter = onlyCaps.count(x)
xDict[x] = numLetter
del xDict["key"]
getMax(xDict)
#get highest value in dict
def getMax(xDict):
Key_max = max(xDict, key = lambda x: xDict[x])
data = xDict.pop(Key_max)
maxLoop(xDict, Key_max, data)
#Loop through dict
def maxLoop(xDict, Key_max, data):
if data != 0:
print(Key_max, data)
getMax(xDict)
else:
pass
start()