#We've written the function, sort_with_bubbles, below. It
takes
#in one list parameter, lst. However, there are two problems
in
#our current code:
# - There's a missing line
# - There's a semantic error (the code does not raise an
# error message, but it does not perform correctly)
#
#Find and fix these problems! Note that you should only need
#to change or add code where explicitly indicated.
#
#Hint: If you're stuck, use an example input list and trace
#the code and how it modifies your list on paper. For
#example, try writing out what happens to the following list:
#
# [34, 16, 2, 78, 4, 6, 1]
def sort_with_bubbles(lst):
#Set swap_occurred to True to guarantee the loop runs once
swap_occurred = True
#Run the loop as long as a swap occurred the previous time
while swap_occurred:
#Start off assuming a swap did not occur
swap_occurred = False
#For every item in the list except the last one...
for i in range(len(lst) - 1):
#If the item should swap with the next item...
if lst[i] > lst[i + 1]:
#Then, swap them! But these lines aren't
#quite right: fix this code!
temp = lst[i]
lst[i] = lst[i + 1]
lst[i+1] = temp
#One more line is needed here; add it!
swap_ocurred = True
return lst
#Below are some lines of code that will test your
function.
#You can change the value of the variable(s) to test your
#function with different inputs.
#
#If your function works correctly, this will originally
#print: [1, 2, 3, 4, 5]
print(sort_with_bubbles([5, 3, 1, 2, 4]))
why is this not working?
# We've written the function, sort_with_bubbles, below. It takes
# in one list parameter, lst. However, there are two problems in
# our current code:
# - There's a missing line
# - There's a semantic error (the code does not raise an
# error message, but it does not perform correctly)
#
# Find and fix these problems! Note that you should only need
# to change or add code where explicitly indicated.
#
# Hint: If you're stuck, use an example input list and trace
# the code and how it modifies your list on paper. For
# example, try writing out what happens to the following list:
#
# [34, 16, 2, 78, 4, 6, 1]
def sort_with_bubbles(lst):
# Set swap_occurred to True to guarantee the loop runs once
swap_occurred = True
# Run the loop as long as a swap occurred the previous time
while swap_occurred:
# Start off assuming a swap did not occur
swap_occurred = False
# For every item in the list except the last one...
for i in range(len(lst) - 1):
# If the item should swap with the next item...
if lst[i] > lst[i + 1]:
# Then, swap them! But these lines aren't
# quite right: fix this code!
temp = lst[i]
lst[i] = lst[i + 1]
lst[i + 1] = temp
# One more line is needed here; add it!
swap_occurred = True # You were using a different variable here..
return lst
# Below are some lines of code that will test your function.
# You can change the value of the variable(s) to test your
# function with different inputs.
#
# If your function works correctly, this will originally
# print: [1, 2, 3, 4, 5]
print(sort_with_bubbles([5, 3, 1, 2, 4]))

#We've written the function, sort_with_bubbles, below. It takes #in one list parameter, lst. However, there are...
Python3: Write the function findLongestStreak(lst) which takes a list of numbers, lst, and returns the longest streak of numbers which occur in the list. A streak of numbers is a list of numbers where each number is one greater than the one that occurred before it- for example, [4, 5, 6, 7]. So findLongestStreak([3, 4, 8, 2, 3, 4, 5, 7, 8, 9]) would return [2, 3, 4, 5]. If there is more than one streak with the longest length,...
Define a function funD2(...) which receives a list lst that contains single letters, single digits and single special characters (and the list contains at least one element of each type). The function returns a string that contains the last letter and the last special character of the list, where each is repeated as many times as the sum of all digits in the list. As an example, the following code fragment: lst = ["a","b","c", 1, 2, "$","%"] print (funD2(lst)) should...
The following lines of code are supposed to add elements to a list, one at a time. However, they do not seem to work correctly. Fix each line so that all elements are able to be appended one at a time. Given code: things = [] things = things.append("Dogs") things = things.append("Cups") things = things.append("Cards") things = things.append("Petals") things = print(things) do in python
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...
Using a sort method and my previous code (put inside of addHours method if possible), how would I get the list of each employee's total hours to display in order of least amount of hours to greatest. An explanation for each step would also be great. import random #Create function addHours def addHours(lst): #Display added hours of employees print("\nEmployee# Weekly Hours") print("----------------------------") print(" 1 ",sum(lst[0])) print(" 2 ",sum(lst[1])) print(" 3 ",sum(lst[2])) #Create main function def main(): #Create first empty list...
IN PYTHON Implement a function printSeqs() that accepts a list of name lst and prints the following sequences. The sequences are printed by the for loops found in the function. The information below shows how you would call the function printSeqs() and what it would display: Write a for loop that iterates through a list of names and print a greeting for each name in the list. Request from the user a positive integer n and prints all the positive...
#Write a function called next_fib. next_fib should take #have two parameters: a list of integers and a single integer. #For this description, we'll call the single integer n. # #next_fib should modify the list to add the next n pseudo- #Fibonacci numbers to the end of the sequence. A pseudo- #Fibonacci number is the sum of the previous two numbers in #the sequence, but in our case, the previous two numbers may #not be the original numbers from the Fibonacci...
Python homework Write a function called insert_value(my_list, value, insert_position) that takes a list, a value and an insert_position as parameters. The function returns a copy of the list with the value inserted into the list (my_list) at the index specified by insert_position. Check for the insert_position value exceeding the list (my_list) bounds. if the insert_position is greater than the length of the list, insert the value at the end of the list. if the insert_position is less than or equal...
I need help with this python programming assignment
please double check the indentations
For this task you're going to write a function that joins strings from a list. The function called join ) has one formal parameter and one optional parameter. Recall that an optional parameter is like end or sep in the print( function. You don't have to use it because there's a default value. For the print () function, e.g., \'n' (newline) is the default value for end....
Create a new program in Mu and save it as ps4.5.2.py and take the code below and fix it as indicated in the comments: # Do not change the line of code below. It's at the top of # the file to ensure that it runs before any of your code. # You will be able to access french_dict from inside your # function. french_dict = {"me": "moi", "hello": "bonjour", "goodbye": "au revoir", "cat": "chat", "dog": "chien", "and": "et"} #...