PYTHON CODE
Given that play_list has been defined to be a list, write an expression that evaluates to a new list containing the elements at index 0 through index 4 play_list. Do not modify play_list.
code:
# Define a play_list
play_list = [12, 34, 23, 45, 9, 10, 15,78,54,7]
# Display play_list elements
print('play_list: ', play_list)
# This expression evaluates to a new list
# containing the elements at index 0 through
# index 4 of play_list
new_list = [ play_list[index] for index in range(0, 5) ]
# Display new_list elements
print('new_list: ',new_list)
----------------------
PYTHON CODE Given that play_list has been defined to be a list, write an expression that...
Python recursive function: Given an ordered list L. A permutation of L is a rearrangement of its elements in some order. For example (1,3, 2) and (3, 2, 1) are two different permutations of L=(1,2,3). Implement the following function: def permutations (lst, low, high) The function is given a list 1st of integers, and two indices: low and high (lows high), which indicate the range of indices that need to be considered The function should return a list containing all...
Python program - Write a Python program, in a file called sortList.py, which, given a list of names, sorts the names into alphabetical order. Use a one dimensional array to hold the list of names. To do the sorting use a simple sorting algorithm that repeatedly takes an element from the unsorted list and puts it in alphabetical order within the same list. Initially the entire list is unsorted. As each element is placed in alphabetical order, the elements in...
python code The power set of a list L is a list containing all possible combinations of the elements of L. For example, the power set of [1, 2, 3] is [[], [1], [2], [3], [1, 2], [1, 3], [2, 3], [1, 2, 3]]. Section 9.3 of your textbook describes a (subtle) algorithm for generating the power set. • Read and understand the structure of the code in Figure 9.6 • Write (your own) function powerset(L) that generates and returns...
Assume the variable LIST is defined as a list of numbers. Write a code segment that utilizes a loop to total up all of the numbers in the list up to, but not including, the first negative number. Store the result in the variable TOTAL. % test cases % LIST = [ 1 4 6 -2 7 9]; TOTAL = 11; % LIST = [ -2 4 5 7 9]; TOTAL = 0; % your code segment here %----------------------- %...
Python: We defined two variables, x = 'Python' and y = '3.0'. Write code to concatenate the two numbers (the result should be 'Python3.0').
(Python)Implement the function deep_list, which takes in a list, and returns a new list which contains only elements of the original list that are also lists. Use a list comprehension. def deep_list(seq): "" "Returns a new list containing elements of the original list that are lists. >>> seq = [49, 8, 2, 1, 102] >>> deep_list(seq) [] >>> seq = [[500], [30, 25, 24], 8, [0]] >>> deep_list(seq) [[500], [30, 25, 24], [0]] >>> seq = ["hello", [12, [25], 24],...
•Write a regular expression for both a zip code and a phone number in python.
PYTHON: Write an expression that will cause the following code to print "18 or less" if the value of user_age is 18 or less. Write only the expression. Sample output with input: 17 18 or less
Write a Python function fun3(e) to update a list of numbers e such that the first and last elements have been exchanged. The function needs to also return multiplication of elements of e. You should assume that the list e has at least 2 elements. Example: >>>lst = [4, 1, 2, -1] >>>fun3(list) -8 >>>lst [-1, 1, 2, 4] *We are an intro to CS class so please do not use anything too advance or fancy. Stick to basics. Right...
C# code Arrays and Linked Lists: Write C++/Java/C#/Python code to declare an array of linked lists of any primitive type you want. (Array of size 2020) (This could be based on MSDN libraries or the lab) – you do not need to instantiate any of the linked lists to contain any actual values. Paste your code for that here (this should only be one line) Based on your code or the lab from 4 or your doubly linked list from...