Write only a python function definition for a function that takes two strings values as its parameters , and if the first parameter alphabetically comes later in a dictionary than the second parameter then the function returns the length of the first parameter, otherwise the function returns the negative of the length of the second parameter.
Name your function fA.
For instance :
fA(“do”,”can”) returns 2
def fA(s1,s2):
if(s1>s2):
return len(s1)
else:
return -len(s2)
# Testing
print(fA("do","can"))

2
Write only a python function definition for a function that takes two strings values as its...
Python 3.7.3 ''' Problem 3 Write a function called names, which takes a list of strings as a parameter. The strings are intended to represent a person's first and last name (with a blank in between). Assume the last names are unique. The function should return a dictionary (dict) whose keys are the people's last names, and whose values are their first names. For example: >>> dictionary = names([ 'Ljubomir Perkovic', \ 'Amber Settle', 'Steve Jost']) >>> dictionary['Settle'] 'Amber' >>>...
Python: Write a function named "sort_by_length" that takes a list/array of strings as a parameter and sorts the strings by their length
write C code that uses pointers, arrays, and C strings. 3. Write a function called pow_xy. The function should be passed 2 parameters, as illustrated in the prototype below. int pow_xy(int *xptr, int y); Assuming that xptr contains the address of variable x, pow_xy should compute x to the y power, and store the result as the new value of x. The function should also return the result. Do not use the built-in C function pow. For the remaining problems,...
In python,write a function nameSet(first, last) that takes a person's first and last names as input, and returns a tuple of three strings: the first string gives the union of all letters in the first and last names (no duplication though). The second string gives the intersection of letters in the first and last names, i.e. the common letters. If there are no common letters, then the second string is empty (''). The third string gives the symmetric difference between...
PYTHON The function longest that returns the longest of two strings. The function count_over that takes a list of numbers and an integer nand returns the count of the numbers that are over n. The function bmi that takes two parameters height and weight and returns the value of the body mass index: a person's weight in kg divided by the square of their height in meters. def longest(string1, string2): """Return the longest string from the two arguments, if the...
Python 3
Define a function below, get_subset, which takes two arguments: a dictionary of strings (keys) to integers (values) and a list of strings. All of the strings in the list are keys to the dictionary. Complete the function such that it returns the subset of the dictionary defined by the keys in the list of strings. For example, with the dictionary ("puffin": 5, "corgi": 2, "three": 3) and the list ("three", "corgi"), your function should return {"corgi": 2, "three"...
Need in Python! Write a function definition named power that takes two formal parameters which can be assumed to be any numeric type. The first parameter is called base, the second is called exponent. The function should return the result of the base raised to the exponent power. You may not use any Python math library functions inside your function. You may create your own code to test the function in an IDE if you wish. HINT: The exponent operator in...
Python 5. Write a function named grade_components that has one parameter, a dictionary. The keys for the dictionary are strings and the values are lists of numbers. The function should create a new dictionary where the keys are the same strings as the original dictionary and the values are tuples. The first entry in each tuple should be the weighted average of the non-negative values in the list (where the weight was the number in the 0 position of the...
How do I write a one-line (excluding function definition) python function make_filter(limit), which takes in an integer limit, and returns a function that takes in a list of strings, and returns a copy of the list with all strings shorter than limit characters removed. make_filter must be exactly one line of Python code, not including the function signature line ( def make_filter(limit): ) example: >>> filter5 = make_filter(5) >>> filter5(['', 'a', 'aa', 'aaa', 'aaaa', 'aaaaa', 'aaaaaa']) ['aaaaa', 'aaaaaa'] >>> filter2...
solve with python
Write a recursive function recStringWithLenCount() that takes a
one-dimensional list of strings as a parameter and returns the
count of strings that have at least the length of second parameter
passed into the function that are found in the list. Recall that
you can determine whether an item is a string by writing type(item)
== str. The only list functions you are allowed to use are len(),
indexing (lst[i] for an integer i), or slicing (lst[i:j] for...