Create a script that invert a list and give the biggest n numbers of a list
- User
Create a script that invert a list and give the biggest n numbers of a list
Assistant
def invert_list(list1): """Inverts the order of a list.""" # Get the length of the list. list_length = len(list1) # Create a new list to store the inverted list. inverted_list = [] # Iterate over the list in reverse order. for i in range(list_length - 1, -1, -1): # Append the element at the current index to the inverted list. inverted_list.append(list1[i]) # Return the inverted list. return inverted_list def get_biggest_n_numbers(list1, n): """Returns the biggest n numbers in a list.""" # Sort the list in descending order. list1.sort(reverse=True) # Return the first n elements of the sorted list. return list1[:n] # Create a list of numbers. list1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] # Invert the list. inverted_list = invert_list(list1) # Get the biggest 5 numbers in the list. biggest_5_numbers = get_biggest_n_numbers(inverted_list, 5) # Print the inverted list and the biggest 5 numbers. print("Inverted list:", inverted_list) print("Biggest 5 numbers:", biggest_5_numbers)
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.