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
|
#!/usr/bin/env python
# -------------------------------------
# AUTHOR: Robert DiCicco
# DATE : 2023-06-13
# Challenge 221 Task 1 Good Strings ( Python )
# -------------------------------------
total_score = 0
words = [["cat", "bt", "hat", "tree"], ["hello", "world", "challenge"]]
chlist = ["atach","welldonehopper"]
cnt = 0
listcnt = 0
for wds in words:
print("Input: @words = ",wds)
chars = chlist[cnt]
total_score = 0
score = 0
for w in wds:
ln = len(w)
for mycnt in range(0,ln):
tst = w[mycnt]
if tst in chlist[listcnt]:
score += 1
else:
break
if score == ln:
print(w)
total_score += score
score = 0
print("\tTotal: ",total_score)
print("")
listcnt += 1
# -------------------------------------
# SAMPLE OUTPUT
# python .\GoodStrings.py
# Input: @words = ['cat', 'bt', 'hat', 'tree']
# cat
# hat
# Total: 6
# Input: @words = ['hello', 'world', 'challenge']
# hello
# world
# Total: 10
# -------------------------------------
|