import numpy as np
def pagerank(M, num_iterations=100, d=0.85):
N = M.shape[1]
v = np.random.rand(N, 1)
v = v / np.linalg.norm(v, 1)
iteration = 0
while iteration < num_iterations:
iteration += 1
v = d * np.matmul(M, v) + (1 - d) / N
return v
This method gets vowels (‘a’, ‘e’, ‘i’, ‘o’, ‘u’) found in a string.
#make a function:
def get_vowels(string):
#return is the keyword which means function have to return value:
return [each for each in string if each in 'aeiou']
#assign the words and function will return vowels words.
get_vowels('foobar') # ['o', 'o', 'a']
get_vowels('gym') # []
keys, values)) # {'a': 2, 'c': 4, 'b': 3}
#make a function: def is the keyword for the function:
def to_dictionary(keys, values):
#return is the keyword that tells program that function has to return value
return dict(zip(keys, values))
# keys and values are the lists:
keys = ["a", "b", "c"]
values = [2, 3, 4]
my_list = [27, 5, 9, 6, 8]
def RemoveValue(myVal):
if myVal not in my_list:
raise ValueError("Value must be in the given list")
else:
my_list.remove(myVal)
return my_list
print(RemoveValue(27))
print(RemoveValue(27))
Comments