Question

In: Computer Science

python pls create a function party_place: that search the dictionary and figure out where they party...

python pls

create a function party_place: that search the dictionary and figure out where they party in that day.

For example

def party_place(dict2: dict, date: (int,int,int)):

dict1= {'fire1': {(2000,5,20,480) : ('Aaron', 25, 300, ( 0, 300)),
(2000,5,20,720) : ('Baily', 45, 1500, (1500,500)),
(2000,5,21,490) : ('Aaron', 35, 500, (1300,500)) },
'fire2': {(2000,5,20,810) : ('Baily', 45, 1400, (600,1600)),
(2000,5,20,930) : ('Baily', 43, 1800, ( 0, 0)) }}

output

print(party_place(dict1, (2000,5,20,720))

= ['fire1', 'fire2']

print(party_place(dict1, (2000,5,21,720))

= ['fire1']

print(party_place(dict1, (2000,5,22,720))

= []

Solutions

Expert Solution

def party_place(dict2: dict, date: (int, int, int, int)):

    # remove last part

    date = date[:3]

    # list to return

    places = []

    # iterate over dict2

    for place in dict2:

        dates = dict2[place]

        # remove last part from all dates

        dates = [d[:3] for d in dates]

        # if given date is present in current place

        if date in dates:

            # add to places

            places.append(place)

    return places


dict1 = {'fire1': {(2000, 5, 20, 480): ('Aaron', 25, 300, (0, 300)),

                   (2000, 5, 20, 720): ('Baily', 45, 1500, (1500, 500)),

                   (2000, 5, 21, 490): ('Aaron', 35, 500, (1300, 500))},

         'fire2': {(2000, 5, 20, 810): ('Baily', 45, 1400, (600, 1600)),

                   (2000, 5, 20, 930): ('Baily', 43, 1800, (0, 0))}}


print(party_place(dict1, (2000, 5, 20, 720)))  # =['fire1', 'fire2']

print(party_place(dict1, (2000, 5, 21, 720)))  # =['fire1']

print(party_place(dict1, (2000, 5, 22, 720)))  # =[]

.

Screenshot:

Output:

.


Related Solutions

Python pls Create a function dict_sum. This function takes a dictionary and sums up the values...
Python pls Create a function dict_sum. This function takes a dictionary and sums up the values in the dictionary. For example: dict1 = {1: {'una': 5, 'dos': 7, 'tres': 9, 'quar' : 11}, 2: {'dos':2, 'quar':4}, 3:{'una': 3, 'tres': 5}, 4:{'cin': 6}, 5:{'tres': 7 , 'cin': 8}} dict2 = {300:{'s': 300}, 400:{'s': 100, 'g': 100, 'p': 100}, 500: {'s': 50 ,'m': 400, 'p':30, 'i': 50}, 600: {'s': 40, 'i': 400}, 700: {'m': 100, 'p': 50}} def dict_sum(db): should give output...
Python create a function tryhard and print out the dictionary as a string form. For example...
Python create a function tryhard and print out the dictionary as a string form. For example def tryhard(d:dict): #Code here input: d = {'first': {}, 'second': {'1': {'move'}, '0': {'move', 'slow'}}, 'third': {'1': {'stop'}}} output = " first movie: [ ]\n third movie: [('1', ['stop'])]\n second movie: [('0', ['slow', 'move']), ('1', ['move'])]\n"
PYTHON PLS 1) Create a function search_by_pos. This function only has one return statement. This function...
PYTHON PLS 1) Create a function search_by_pos. This function only has one return statement. This function returns a set statement that finds out the same position and same or higher skill number. This function searches the dictionary and returns the same position and same or higher skill level. The function output the set statements that include the position only. For example input : dict = {'Fiora': {'Top': 1, 'Mid': 4, 'Bottom': 3},'Olaf': {'Top': 3, 'Mid': 2, 'Support': 4},'Yasuo': {'Mid': 2,...
Python pls create a function called search_position. This function returns a list. team1 = {'Fiora': {'Top':...
Python pls create a function called search_position. This function returns a list. team1 = {'Fiora': {'Top': 1, 'Mid': 4, 'Bottom': 3},'Olaf': {'Top': 3, 'Mid': 2, 'Support': 4},'Yasuo': {'Mid': 2, 'Top': 5},'Shaco': {'Jungle': 4, 'Top': 2, 'Mid': 1}} def search_position(team1): returns [(5, [('Top', ['Yasuo'])]), (4, [('Mid', ['Fiora']), ('Support',['Olaf']), ('Jungle',['Shaco'])])   (3, [('Bottom', ['Fiora']), ('Top', ['Olaf'])]), (2, [('Mid', ['Olaf','Yasuo']), ('Top', ['Shaco'])]), (1, [('Mid', ['Shaco'])])]
Python pls Create a function party_freq(dicto:dict): this function returns a list inside tuple that how many...
Python pls Create a function party_freq(dicto:dict): this function returns a list inside tuple that how many times each person party in the day. For example def party_freq(dicto:dict) -> [(str,{(int,int,int): int})]: #code here input dict1 ={'fire1': {(2000,5,20,480) : ('Aaron', 25, 300, ( 0, 300)), (2000,5,20,720) : ('Baily', 45, 1500, (1500,500)), (2000,5,21,490) : ('Aaron', 35, 500, (1300,500)) }, 'fire2': {(2000,5,20,810) : ('Baily', 45, 1400, (600,1600)), (2000,5,20,930) : ('Baily', 43, 1800, ( 0, 0)) }} output [('Aaron', {(2000,5,20): 1, (2000,5,21): 1}), ('Baily', {(2000,5,20):...
PYTHON CODING Create a method (sortTraversal) for a Binary Search Tree that prints out the Binary...
PYTHON CODING Create a method (sortTraversal) for a Binary Search Tree that prints out the Binary Search Tree in ascending or deceasing order. The order type is an input to the method and can be "ascending" or "descending". The ascending input would return the node values of the tree beginning with the smallest and ending with the largest, descending returns the opposite. Discuss method's Big-O notation. Add proper and consistent documentation to identify code sections or lines to clearly identify...
Write code to create a Python dictionary called class. Add two entries to the dictionary: Associate...
Write code to create a Python dictionary called class. Add two entries to the dictionary: Associate the key 'class_name' with the value 'MAT123', and associate the key 'sect_num' with '211_145'
*Python* 1.1) Create an empty dictionary called 'addresses'. The dictionary you just created will map names...
*Python* 1.1) Create an empty dictionary called 'addresses'. The dictionary you just created will map names to addresses. A person's name (stored as a string) will be the KEY and that person's address (stored as a string) will be the VALUE. 1.2) Insert into the dictionary 'addresses' the names and addresses of two (possibly imaginary) friends of yours. 1.3) Create a second empty dictionary called 'ages'. The dictionary you just created will map names to ages. A person's name (stored...
Use Python for this quetions: Write a python functions that use Dictionary to: 1) function name...
Use Python for this quetions: Write a python functions that use Dictionary to: 1) function name it addToDictionary(s,r) that take a string and add it to a dictionary if the string exist increment its frequenc 2) function named freq(s,r) that take a string and a record if the string not exist in the dictinary it return 0 if it exist it should return its frequancy.
in Python 3, I need to search a dictionary for the matching key while ignoring case...
in Python 3, I need to search a dictionary for the matching key while ignoring case of the string and the key. then print the dictionary item in it's original case. here is the code I have so far but the compiler isn't liking that the name string is lowercase ``` dictionary = {"Dan Smith": {"street":"285 Andover Lane", "city":"Pompano Beach", "state":"FL", "zip":"33060"},"Parker Brady": {"street":"7416 Monroe Ave.", "city":"Windsor", "state":"CT", "zip":"07302"}} name ="dan smith" line= dict(filter(lambda item: name.lower() in item[0], dictionary.items())) print("Street:%5s...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT