PYTHON PROBLEM
Define a function generate_kv_strings( dictionary ) that creates
and return a list where the element is a string representing a
key-value pair in the format "key: value". Your solution must use a
list comprehension.
Hint: Remember that you need to convert each key and value into a
str before concatenating them, in case they are of a different
type.
Example Usage:
states = {'Florida': 'FL', 'Oregon': 'OR', 'California': 'CA', 'New
York': 'NY', 'North Carolina': 'NC'}
numbers = {'four': 4, 'three': 3, 'two': 2, 'one': 1}
print generate_kv_strings( states )
print generate_kv_strings( numbers )
Run > Run Module
['California: CA', 'New York: NY', 'Florida: FL', 'North Carolina:
NC', 'Oregon: OR']
['four: 4', 'one: 1', 'three: 3', 'two: 2']
# python code to a list where the element is a string representing a key-value pair in the format "key: value"
def generate_kv_strings(states):
list = []
# iterate over dictionary
for key in states:
# create a string of key value
pair
string = str(key) + ": " +
str(states[key])
# append to list
list.append(string)
return list
states = {'Florida': 'FL', 'Oregon': 'OR', 'California': 'CA', 'New
York': 'NY', 'North Carolina': 'NC'}
numbers = {'four': 4, 'three': 3, 'two': 2, 'one': 1}
print generate_kv_strings(states)
print generate_kv_strings( numbers )
'''
output:
['California: CA', 'New York: NY', 'Florida: FL', 'North
Carolina: NC', 'Oregon: OR']
['four: 4', 'one: 1', 'three: 3', 'two: 2']
'''

PYTHON PROBLEM Define a function generate_kv_strings( dictionary ) that creates and return a list where the...
It's python. Please don't forget to print alpha-sorted states. Not random. Thank you // USPresdients.txt KY Abraham_Lincoln SC Andrew_Jackson NC Andrew_Johnson HI Barack_Obama OH Benjamin_Harrison AR Bill_Clinton VT Calvin_Coolidge VT Chester_A_Arthur NY Donald_Trump TX Dwight_D_Eisenhower NY Franklin_D_Roosevelt NH Franklin_Pierce MA George_H_W_Bush CT George_W_Bush VA George_Washington NE Gerald_R_Ford NJ Grover_Cleveland MO Harry_S_Truman IA Herbert_Hoover OH James_A_Garfield PA James_Buchanan NC James_K_Polk VA James_Madison VA James_Monroe GA Jimmy_Carter MA John_Adams MA John_F_Kennedy MA John_Quincy_Adams VA John_Tyler TX Lyndon_B_Johnson NY Martin_Van_Buren NY Millard_Fillmore CA ...
JAVA: File USCapitals.txt is here: Alabama, Montgomery Alaska, Juneau Arizona, Phoenix Arkansas, Little Rock California, Sacramento Colorado, Denver Connecticut, Hartford Delaware, Dover Florida, Tallahassee Georgia, Atlanta Hawaii, Honolulu Idaho, Boise Illinois, Springfield Indiana, Indianapolis Iowa, Des Moines Kansas, Topeka Kentucky, Frankfort Louisiana, Baton Rouge Maine, Augusta Maryland, Annapolis Massachusettes, Boston Michigan, Lansing Minnesota, Saint Paul Mississippi, Jackson Missouri, Jefferson City Montana, Helena Nebraska, Lincoln Nevada, Carson City New Hampshire, Concord New Jersey, Trenton New York, Albany New Mexico, Santa Fe...
in Python, define a function named filterOut with three parameters. The first argument passed to the function should be a list of dictionaries (the data), the second a string (a dictionary key), and the third another string (a dictionary value). This function must return a list of all the dictionaries from the input list which do NOT contain the indicated key:value pairing. in Python, define a function named filterInRange with four parameters. The first argument passed to the function should...
With the multiple linear regression equation in (2), what will
be the alumni-giving rate with the graduation rate as 85%, 60% of
classes with fewer than 20 students, and student-faculty ratio as
12? (20%).
State Graduation Rate 85 79 93 85 75 Alumni Giving Rate 25 % of Classes Student-Faculty Under 20 Ratio 39 13 68 8 60 8 33 40 65 3 10 46 28 67 72 52 8 31 89 90 45 69 72 12 7 13 10...
I am trying to do this assignment: Write a program that reads a list of concepts/strings from the LIST.txt text file (one concept per line), stores them into an array of strings, and then prints the following: 1.Prints a heading “LIST1:” and then prints all the concepts from the array, one concept per line 2.Prints a heading “LIST2:” and then prints all the concepts from the array that do not contain spaces, one concept per line 3.Prints a heading “LIST3:”...
Could anyone help add to my python code? I now need to calculate the mean and median. In this programming assignment you are to extend the program you wrote for Number Stats to determine the median and mode of the numbers read from the file. You are to create a program called numstat2.py that reads a series of integer numbers from a file and determines and displays the following: The name of the file. The sum of the numbers. The...
Alumni donations are an important source of revenue for college and universities. If administrators could determine the factors that could lead to increases in thepercentage of alumni who make a donation, they might be able to implement policies that could lead to increased revenues. Research shows that students who are moresatisfied with their contact with teachers are more likely to graduate. As a result, one might suspect that smaller class sizes and lower student-faculty ratios mightlead to a higher percentage...
Write a French/English dictionary lookup program. Read a list of pairs of English and French words from a file specified by the user. English/French words should be exact matches (don't try to find partial matches). Use the supplied EnglishFrenchDictionary.java class as your main class. Fill in the missing code in the DictionaryTable.java class to read the input file and perform the searches. Add code to the DictionaryTable read() method to: read pairs of lines (English word is on the first...
Complete function long_list_printer.print_list(). When it's
finished, it should be able to print this list,
a = [
[93, 80, 99, 72, 86, 84, 85, 41, 69, 31],
[15, 37, 58, 59, 98, 40, 63, 84, 87, 15],
[48, 50, 43, 68, 69, 43, 46, 83, 11, 50],
[52, 49, 87, 77, 39, 21, 84, 13, 27, 82],
[64, 49, 12, 42, 24, 54, 43, 69, 62, 44],
[54, 90, 67, 43, 72, 17, 22, 83, 28, 68],
[18, 12, 10,...
JAVA Create a Governor class with the following attributes: name : String party - char (the character will be either D, R or I) ageWhenElected : int Create a State class with the following attributes: name : String abbreviation : String population : long governor : Governor Your classes will have all setters, getters, typical methods to this point (equals(), toString()) and at least 3 constructors (1 must be the default, 1 must be the copy). You will be turning...