Implement a group_by_owners function that:
in:
out:
{'Randy': ['Input.txt', 'Output.txt'], 'Stan': ['Code.py']}.http://code.activestate.com/recipes/252143-invert-a-dictionary-one-liner/
def group_by_owners(files):
inv = {}
for k, v in files.items():
keys = inv.setdefault(v, [])
keys.append(k)
return inv
Implement the function find_roots to find the roots of the quadratic equation: ax2 + bx + c = 0.
The function should return a tuple containing roots in any order.
The roots of the quadratic equation can be found with the following formula: A quadratic equation.
in: find_roots(2, 10, 8)
out: (-1, -4) or (-4, -1) as the roots of the equation 2x2 + 10x + 8 = 0 are -1 and -4.
import numpy as np
import cmath
# https://docs.scipy.org/doc/numpy/reference/generated/numpy.roots.html
def find_roots(a, b, c):
return np.roots(np.array([a, b, c]))
# https://www.programiz.com/python-programming/examples/quadratic-roots
def find_roots(a, b, c):
d = (b**2) - (4*a*c)
# find two solutions
sol1 = (-b-cmath.sqrt(d))/(2*a)
sol2 = (-b+cmath.sqrt(d))/(2*a)
return f'{sol1}, {sol2}'
l = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
data = [[3,7,2],[1,4],[9,8,7,10]]
list(map(sum, data))
# [12, 5, 34]
def rowsum(matrix):
"""
:param matrix (list): A list of lists where each inner list represents a row.
:returns: (list) A list containing the sum of each row.
"""
return list(map(sum, matrix))
if __name__ == "__main__":
files = {
'Input.txt': 'Randy',
'Code.py': 'Stan',
'Output.txt': 'Randy'
}
print(group_by_owners(files))
# print(find_roots(2, 10, 8))
print(rowsum(l))