-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path028MixFunctionExample.py
More file actions
154 lines (116 loc) · 3.64 KB
/
028MixFunctionExample.py
File metadata and controls
154 lines (116 loc) · 3.64 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
def unique_english_letters(word):
letterList = []
for letter in word:
if letter not in letterList:
letterList.append(letter)
return len(letterList)
######################################################
def count_char_x(word, x):
return word.count(x)
######################################################
def substring_between_letters(word, start, end):
if word.find(start) == -1 or word.find(end) == -1:
return word
else:
return word[word.find(start)+1:word.find(end)]
######################################################
def x_length_words(sentence, x):
sentenceArray = sentence.split()
for word in sentenceArray:
if len(word) < x:
return False
return True
######################################################
def check_for_name(sentence, name):
if name.lower() in sentence.lower():
return True
else:
return False
######################################################
def every_other_letter(word):
every_other = ""
for i in range(0, len(word), 2):
every_other += word[i]
return every_other
######################################################
def reverse_string(word):
return word[::-1]
######################################################
def make_spoonerism(word1, word2):
firstLetterWord1 = word1[0]
word1 = word2[:1] + word1[1:]
word2 = firstLetterWord1 + word2[1:]
return word1 + " " + word2
######################################################
def add_exclamation(word):
if len(word) >= 20:
return word
else:
while len(word) < 20:
word += "!"
return word
######################################################
def sum_values(my_dictionary):
total = 0
for value in my_dictionary.values():
total += value
return total
######################################################
def sum_even_keys(my_dictionary):
total = 0
for keys in my_dictionary.keys():
if keys % 2 == 0:
total += my_dictionary.get(keys)
return total
######################################################
def add_ten(my_dictionary):
for key in my_dictionary.keys():
my_dictionary[key] += 10
return my_dictionary
######################################################
def values_that_are_keys(my_dictionary):
returnedList = []
for value in my_dictionary.values():
if value in my_dictionary.keys():
returnedList.append(value)
return returnedList
######################################################d
def max_key(my_dictionary):
largest_key = ""
largest_value = float("-inf")
for key, value in my_dictionary.items():
if largest_value < value:
largest_value = value
largest_key = key
return largest_key
######################################################
def word_length_dictionary(words):
dictionaryWords = {}
for word in words:
dictionaryWords[word] = len(word)
return dictionaryWords
######################################################
def frequency_dictionary(words):
freqDictionary = {}
for word in words:
if word not in freqDictionary.keys():
freqDictionary[word] = 1
else:
freqDictionary[word] += 1
return freqDictionary
######################################################
def unique_values(my_dictionary):
seen_values = []
for value in my_dictionary.values():
if value not in seen_values:
seen_values.append(value)
return len(seen_values)
######################################################
def count_first_letter(names):
newDictionary = {}
for key, value in names.items():
if key[0] not in newDictionary.keys():
newDictionary[key[0]] = len(value)
else:
newDictionary[key[0]] += len(value)
return newDictionary