1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Oduvanchick [21]
2 years ago
7

find_cow(name, cows) Given a name and a Python list of Cow objects, return the Cow object with the specified name. If no such Co

w object can be found, return None.
Computers and Technology
1 answer:
nadya68 [22]2 years ago
4 0

Using the computational knowledge in python it is possible to write a code that Given a name and a Python list of Cow objects

<h3>Writting the code in python:</h3>

<em>def load_cows(filename):</em>

<em>      cow_dict = dict()</em>

<em>    f = open(filename, 'r')</em>

<em> </em>

<em>    for line in f:</em>

<em>        line_data = line.split(',')</em>

<em>        cow_dict[line_data[0]] = int(line_data[1])</em>

<em>    return cow_dict</em>

<em>def greedy_cow_transport(cows, limit=10):</em>

<em>       trips = []</em>

<em>    cowsCopy = cows.copy()</em>

<em>    sortedCows = sorted(cowsCopy.items(), key=lambda x: x[1], reverse = True)</em>

<em>    while sum(cowsCopy.values()) > 0:</em>

<em>        ship = []</em>

<em>        total = 0</em>

<em>        for cow, value in sortedCows:</em>

<em>            if cowsCopy[cow] != 0 and value + total <= limit:</em>

<em>                ship.append(cow)</em>

<em>                total += value</em>

<em>                cowsCopy[cow] = 0</em>

<em>        trips.append(ship)</em>

<em>    return trips</em>

<em>def brute_force_cow_transport(cows,limit=10):</em>

<em>     trips = []</em>

<em>     possibilities = []</em>

<em>    for i in power_list:</em>

<em>        ship = []</em>

<em>        for j in i:</em>

<em>            ship_weights = []</em>

<em>            for k in j:</em>

<em>                ship_weights.append(cows[k])</em>

<em>                #print(ship_weights)</em>

<em>            ship.append(sum(ship_weights))</em>

<em>            #print(ship)</em>

<em>        if all(d <= limit for d in ship):</em>

<em>            possibilities.append(i)</em>

<em>      pruned_possibilities = []</em>

<em>    for k in possibilities:</em>

<em>        if k not in pruned_possibilities:</em>

<em>            pruned_possibilities.append(k)</em>

<em>    # now find the minimum list length:</em>

<em>    min_list_len = min(map(len, pruned_possibilities))</em>

<em>    for l in pruned_possibilities:</em>

<em>        if len(l) == min_list_len:</em>

<em>            return l</em>

<em>       </em>

<em>def compare_cow_transport_algorithms():</em>

<em>       greedy_start = time.time()</em>

<em>    greedy_results = greedy_cow_transport(cows, limit = 10)</em>

<em>    greedy_end = time.time()</em>

<em>    print('Greedy Algorithm time:', greedy_end -greedy_start)</em>

<em>    brute_force_start = time.time()</em>

<em>    brute_force_results = brute_force_cow_transport(cows, limit = 10)</em>

<em>    brute_force_end = time.time()</em>

<em>    print('Brute force time:', brute_force_end - brute_force_start)</em>

<em>    print('Greedy Algorithm results:', greedy_results)</em>

<em>    print('Number of trips returned by Greedy Algorithm:', len(greedy_results))</em>

<em>    print('Brute Force Algorithm results:', brute_force_results)</em>

<em>    print('Number of trips returned by Brute Force Algorithm:', len(brute_force_results))</em>

   

See more about python at brainly.com/question/13437928

#SPJ1

You might be interested in
IOS jail broken or Android unrooted which is better to hack with
Ira Lisetskai [31]
IOS Jail Broken - that is more advanced then an android
3 0
3 years ago
Options to rotate cells in excel are available using the _____ button in the alignment group on the home tab.
7nadin3 [17]
Options to rotate cells in excel are available using the orientation button in the alignment group on the home tab. orientation.
7 0
3 years ago
Best app in free to learn python
Allushta [10]

Answer:

Sololearn app

Explanation:

it's very easy to learn python there

4 0
3 years ago
If you were looking for a record in a very large database and you knew the ID number, which of the following would be the most d
dezoksy [38]

Answer:

By the record ID

Explanation:

5 0
3 years ago
John's Plumbing prides itself on excellent customer service, especially during after-hours service calls. They want to connect w
eduard

John's Plumbing prides itself on excellent customer service, especially during after-hours service calls. They want to connect with people who need emergency plumbing services in the middle of the night.

John's Plumbing should configure to <u>Ad scheduling</u> to meet this goal.

Explanation:

  • An ad schedule allows you to display ads or change bids during certain times.
  • Ad schedules are set at the campaign level and direct Google when to run your campaigns. Simply put, your ads won't run during times outside the range you specify.  With ad scheduling, you can set which days of the week you want to run your ads and start/stop times for each day
  • Ad scheduling or Day Parting simply lets you specify certain hours or days of the week you would like your AdWords ads to show.
  • For many years Google AdWords allowed 25 characters for a single headline and 35 characters per line for two lines of description text. Then Google gave us two headlines of 30 characters each and a description line of 80 characters.
  • Dayparting is a pay-per-click (PPC) advertising tactic by which you schedule ads for certain times of day or certain days of the week in order to more effectively target audiences.

4 0
3 years ago
Other questions:
  • In the processes tab of task manager, the ____ tab displays the âworking setâ of a process, or the amount of memory it is active
    12·1 answer
  • A common technique for masking contents of messages or other information traffic so that opponents can not extract the informati
    14·1 answer
  • Wich technology can a website use to allow you to listen to a concert live over the internet?
    10·1 answer
  • Networks that are designed to connect similar computers that share data and software with each other are called:
    10·1 answer
  • Name three types of hard drives, along with its speed and size.
    8·1 answer
  • discuss the benefits of normalization, and do you think we should normalize our designs to higher levels than 3NF? Why or why no
    9·1 answer
  • this bar is located at the top of your computer school in.Its functions allow you to navigate the web​
    5·2 answers
  • Write a program that takes paragraph from the user and prints all unique words in that paragraph using strings in c++
    5·1 answer
  • What dd command would you use to copy the contents of a partition named /dev/drive1 to another partition, called /dev/backup?
    6·1 answer
  • What is it called when servers on the Internet supply applications as a service, rather than a product
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!