Swap names Complete the following function according to its docstring Note: this function should return None. Its job is to modify the list passed as its argument. 1 def swap_name(name_ list: list[str]) -> None: 'name list contains a single person's name 2. 3. Modify name list so that the first name and last name are swapped. 4. >>> name = [ 'John', 'Smith'] >>> swap_name(name) >>> name ['Smith', 'John'] ['John, 8. Andrew" "Gleeson', 'Smith'] >>> name = 10 >>> swap_name (name) 11 >>> name ['Smith', 'Andrew' Gleeson', John'] 12 6700
Q: Using the ListNode structure introduced in this chapter, write a function void printFirst(ListNode…
A: Given: void printFirst(ListNode *ptr)
Q: 1. Given two lists, 11 and 12, write a program to create a third list 13 by picking an odd-index…
A: As our company guidelines we are not supposed to answer more than three subparts of question and…
Q: (Merging Ordered Lists) Write a program that merges two ordered list objects of integers into a…
A: //c++ program #include<iostream> using namespace std; //structure of list node struct ListNode…
Q: Create a function that determines the elements in a list that can be rearranged to create a sequence…
A: Approach: Sort all the elements. Do a linear scan of the sorted array. If the difference between the…
Q: Write a function list_pass () for the linked list. This function should list all student information…
A: As per the given question, we have to design a C program that take students records like student…
Q: language : c++ question : Create a doubly circular linked list. Write a function in doubly…
A: #include <bits/stdc++.h>using namespace std; // Structure of a Nodestruct Node{ int data;…
Q: C function takes a simply-linked list as an input argument. It modifies the list by moving the last…
A: Lets see the solution.
Q: Two arrays list1 and list2 are strictly identical if they have the same length and list1[i] is equal…
A: Program: // C++ version 14 # include <iostream>using namespace std;// boolean functionbool…
Q: The List method reverse() reverses the elements in the list. In the reverse.py file, complete the…
A:
Q: create_numbers_dictionary(numbers) which takes a list of integers as a Define a function called…
A:
Q: Write a function that returns a new list by eliminating the duplicate values in the list. Use the…
A: note: we are only allowed to solve one question in one post. please post-second question in a…
Q: email address, birthday, etc. Write a program that first takes as input an integer N that represents…
A: Code: import java.util.Scanner; class Main{ public static String getPhoneNumber(String[]…
Q: Dictionary Swap Write a function called dictionary_swap that takes a dictionary as a parameter. It…
A: Given: Dictionary Swap Write a function called dictionary_swap that takes a dictionary as a…
Q: a) Write a function to get the value of the Në node in a Linked List. [Note: The first (N=1) item in…
A: Program: class Node: def __init__(self, data=None): self.data = data self.next = None def…
Q: Problem 3: Prime Number 1. Write a function named is prime which takes a positive integer as input,…
A: Part 1. Here I have created a function is_prime() that takes a number as an input parameter and…
Q: In loop_functions.py, define a function named list_concat that takes a single parameter li.This…
A: The main objective of the program, loop_functions.py is that the program concatenates the string…
Q: The reverse function in Section 10.8 reverses a list by copying it to a new list. Rewrite the…
A: In Python, lists are used to store multiple items in a single variable. Lists are mutable type its…
Q: Write a function that accepts a list as an argument (assume the list contains integers) and returns…
A: Let the function be called calculateSum.
Q: Assume list1 references a list. After the following statement executes, list1 and list2 will…
A: The assertion x = y can address two distinct sorts of assignment in python : Assignment by value…
Q: 2. listAverage() returns the average number in a list. Which of these functions does this correctly?…
A: listaverage() function which return the average of number given in list.
Q: This assignment requires the main function and a custom value-returning function. The…
A: random.randint(200,250) : function imported using "import random" module, returns a random number…
Q: • Question 6) Write a function called RemoveDuplicates() that takes a list sorted in increasing…
A: Your C program is given below as you required with an output.
Q: This assignment requires the main function and a custom value-returning function. The…
A: import random def ending_with_7(lst): return [x for x in lst if abs(x) % 10 == 7] def…
Q: Question 3: Contains N Write a function that takes in a list and a number, and returns whether or…
A: for searching a value in list use the in operator, which will return the Boolean value True, if the…
Q: Dictionary-Returned Function a) Define a function, dictSqrt() with a parameter, x: 1) Create a…
A: Here, we have to write a python program for the given problem.
Q: Notice that all of the data in the inner lists are represented as strings. You are to write the…
A: Step 1: Define is_number() function which checks whether the passed value is a number and returns…
Q: Use the function design recipe to develop a function named count_odds. The function takes a list of…
A:
Q: Complete the following function. Note that neither item_list nor index_list should be mutated. 1 | 2…
A: The program is written in python. You can check the screenshot for the correct indentation. Please…
Q: Write a function named get_replacement that takes as arguments a character c and 2 lists of…
A: The Answer is
Q: C++ language. Using the coding prepared below, add and create the Undo last pop, Display undo list…
A: #include<iostream>#include<iomanip>#include<ctype.h> using namespace std; char…
Q: 5. select_lines_from_file In this function, we will open a file for reading, look at each line in…
A: def select_lines_from_file(filename, word): fin = open(filename, 'r') Lines = fin.readlines()…
Q: Add 3 parameters to each function in the code below. *********************************************…
A: Random list created : [3, 2, 5, 6, 1] Specify what operations you wanna perform on the…
Q: Task 3: Write a function that counts and returns 'A' grades which are stored in the linked list. Use…
A: As per the given question, we have to design a function that counts the number of 'A' grades that…
Q: program7.py This assignment requires the main function and a custom value-returning function. The…
A: Custom function fun7(): Takes a list of random integers as its argument A loop is used to iterate…
Q: In SML, combine the two separate code and rewrite into a single function named union that returns…
A: If you assume that a function union: ''a list * ''a list -> ''a list takes two lists of elements…
Q: Create a user-defined function called duplicates. This function will check to see if a singly linked…
A:
Q: In a program, write a function that accepts two arguments: a list, and a number n. Assume that the…
A: Since programming language not mentioned using python.
Q: Inserting Nodes into the List In the following code (This is Code By C) : there are 3 functions :…
A: void insert_last(){ //create a new node struct node *newNode = malloc(sizeof(struct node));…
Q: create_names_dictionary(initials_list, names_list) which takes a list of initials and a list of…
A: I give the code in Python along with output and code screenshot
Q: The function to be built, amino_acids, must return a list of a tuple and an integer when given a…
A: Here is the code for the above problem
Q: 5. Dictionary-Returned Function a) Define a function, dictSqrt0 with a parameter, x: 1) Create a…
A: Q: Use zip and dict to create a dictionary
Q: You need to edit the same code so as to make it a circular doubly linked list. Implement the…
A: Modified code: #include <iostream>using namespace std;class Node{ public: int data;…
Q: 5. select_lines_from_file In this function, we will open a file for reading, look at each line in…
A: The solution for the above given question is given below:
Q: Write a program that reads a list of integers, and outputs whether the list contains all multiples…
A: Python program for above : # function to check if list has all multiple of 10 def…
Q: 17. The following function takes a parameter that is a list of integers; the list has at least one…
A: The code given in question is: def findLarge(intlist): largest = 0 pos = 0 for i in range(1,…
Q: Use the function design recipe to develop a function named unique_list. The function takes a list of…
A: Note : Since the coding language is not mentioned, I have done the code in Python. Algorithm : Step…
Q: 1.3 dict_get Next, you will implement: char* dict_get (const dict_t* dict, const char* key); his…
A: Using the function Create a dictionary by c programming language. char* dict_get (const dict_t*…
Q: In loop_functions.py, define a function named list_concat that takes a single parameter li. This…
A: Reason for using FOR Instead of WHILE: This is because it is easier to use loops to iterate through…
Q: Pascal triangle! write a function(in OCaml) val nextpascalrow : int list -> int list = that given…
A: Given: Pascal triangle! write a function(in OCaml) val nextpascalrow : int list -> int list =…
Q: Use the Design Recipe to write a function num_negatives that consumes a list-type argument and…
A: Program:""" the below program returns the number of negativeintegers in the list.The list may have…
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 3 images
- program7.pyThis assignment requires the main function and a custom value-returning function. The value-returning function takes a list of random integers as its only argument and returns a smaller list of only the elements that end with 7. This value-returning function must use a list comprehension to create this smaller list.In the main function, code these steps in this sequence: Set random seed to 42 import randomrandom.seed(42) create an empty list that will the hold random integers. use a loop to add 50 random integers to the list. All integers should be between 200 and 250, inclusive. Duplicates are okay. sort the list in ascending order and then use another loop to display all 50 sorted integers on one line separated by spaces. print a slice showing list elements indexed 5 through 10, inclusive. print a second slice showing the final 5 elements in the sorted list. execute the custom function with the entire…program7.pyThis assignment requires the main function and a custom value-returning function. The value-returning function takes a list of random integers as its only argument and returns a smaller list of only the elements that end with 7. This value-returning function must use a list comprehension to create this smaller list.In the main function, code these steps in this sequence: Set random seed to 42 import randomrandom.seed(42) create an empty list that will the hold random integers. use a loop to add 50 random integers to the list. All integers should be between 200 and 250, inclusive. Duplicates are okay. sort the list in ascending order and then use another loop to display all 50 sorted integers on one line separated by spaces. print a slice showing list elements indexed 5 through 10, inclusive. print a second slice showing the final 5 elements in the sorted list. execute the custom function with the entire original list as its sole argument. report the number of elements in…C language. Function write the arraylist_sort function This generic function sorts an array list using the given compare function. l An array list compare Pointer to the function which compares two elements If you cannot write down a generic function which works for all types, write down a function which sorts resturants. If you cannot use function pointers, you can write down multiple functions which sort using different criteria.
- JS Write a function named list_concat that has a single parameter. This parameter will be a list/array. The parameter's entries will be strings. Your function needs to return a string. The returned string's value should be the concatention of all of the entries in the parameter with a space after each entry. Sample test cases: list_concat(["single"]) evaluates to "single list_concat(["limit", "break", "ready"]) evaluates to "limit break ready17. The following function takes a parameter that is a list of integers; the list has at least one element. It is supposed to find the integer that is the largest and find the position of that integer in the list. The function has two incorrect lines of code that make the function compute the results incorrectly. Several lines are highlighted (bold, underlined) which COULD be incorrect. In the following questions, choose the correct line of code that should be in the function. 1 def findlarge(intlist): 2 largest = 0 3 pos = 0 for i in range(1,len(intlist)): if largest > intlist[i: 4 5 largest = intlist[i] pos = i return (largest, pos) 8 Select one of the following to correct a line of code in the function. a. Line 2 should be: largest = -1 b. Line 2 should be: largest = intlist[0] c. Line 4 should be: for i in range(0,len(intlist): %3D d. Line 4 should be: for i in range(1,len(intlist)-1): e. Line 8 should be: return largest 18. Select one of the following to correct a line of code in…struct Node { int data; Node * next; }; Node • head; a. Write a function named addNode that takes in a variable of type int and inserts it at the head of the list. b. Write a function named removeNode that removes a node at the head of the list.
- Homework Assignment-1Topics: Functions, Dictionary, ImportProblem description: Write a python application to simulate an online clothing system. Thepurpose of this assignment is to gain experience in Python dictionary structure, create basicPython functions and import a module.Design solution: The template file contains a list of clothes item sold, each item in the listcontains the item id, name of the item and the prices. The program will generate an items_dictwhere each key is the item id of the cloth and the values will be a list of item name and priceinformation. A customer will be presented with a main menu with 4 different options: displayall items, add an item to cart, checkout and exit the program. A customer can buy an item byentering the ID of the item. This program implements a dictionary called cart, where each key isthe item id and the values are the list of name, price and quantity that user chooses topurchase. The program keeps repeating by displaying the main menu to…Using the ListNode structure introduced in this chapter, write a function void printFirst(ListNode *ptr)that prints the value stored in the first node of a list passed to it as parameter. The function should print an error message and terminate the program if the list passed to it is empty.FUNCTION ONE: MAINO In this lab we will create three functions. The first will be called main. Main will simply be the first function executed and will call the other two funetions. It will take in no arguments and will only create an empty list and call the other two functions. FUNCTION TWO: GETDATAO Getdata() will take in a list and then prompt the user to enter a song as a string in the format of song-band. You may assume the user will correctly enter this data. These songs will be appended to our list. The user can continue entering songs until they enter "exit". FUNCTION THREE: PLAYRANDOMO PlayRandom() will take in a list. It will then generate a random number and use it as index to select a random song to print "Now Playing: RandomSongHere". SAMPLE OUTPUT Enter a song title and band (song-band) or exit to quit: I Found- Amber Run Enter a song title and band (song-band) or exit to quit: Bark At The Moon-Ozzy Osbourne Enter a song title and band (song-band) or exit to quit: Real…
- If you have the following node declaration:struct Node {int number;struct Node * next;};typedef struct Node node;node *head,*newNode;Write a C program that contains the following functions to manipulate this linked list : 3. A function deletes the element in the middle of the list (free this memory location) (if the list has 100 or 101 elements, it will delete the 50th element). The function will take a list as a parameter and return the updated list. 4. 2nd function named changeFirstAndLast that swaps the node at the end of the list and the node at the beginning of the list. The function will take a list as a parameter and return the updated list. 5. 3rd function using given prototype below. This function cuts the first node of the list and adds it to the end as last node. It takes beginning address of the list as a parameter and returns the updated list.node* cutheadaddlast(node* head);Dictionary Swap Write a function called dictionary_swap that takes a dictionary as a parameter. It does not modify the original dictionary, but it creates and returns a new one. Keys from the original dictionary become values in the new one, and values become keys. For example, given the inputs below, your program should return the corresponding values. Input to the Function Returns {'one':1, 'two': 2, 'three':3} {1:'one', 2:'two', 3:'three'} {-1:-10, -2:-20, -3:-30} {-10:-1, -20:-2, -30:-3} {} {}Exercise 6 Two words are anagrams if you can rearrange the letters from one to spell the other. Write a function called is_anagram that takes two strings and returns True if they are anagrams. Exercise 7 Write a function called has_duplicates that takes a list and returns True if there is any element that appears more than once. It should not modify the original list.