Rules:
You may NOT use the following built-in functions.
sort()
sum()
max()
min()
Except for
format()
all string methods are banned. Except for append() and extend()
all list methods are banned. You may not import any module.
Make sure to test your code with a variety of inputs. Do not assume the examples in these directions are reflective of the hidden test cases.
Part 3 Echo (5 Points)
Write a function called echo that takes as argument a list and returns a copy of that list with each element duplicated right after it.
Here are some examples of how your program should behave on Python IDLE.
>>> echo(['a','b','c'])
['a','a','b','b','c','c']
>>> echo(['x','y'])
['x','x','y','y']
>>> echo([85,72,61])
[85,85,72,72,61,61]
>>> echo([85,"abc",6.79])
[85,85,'abc','abc',6.79,6.79]
code:
def echo(l):
res = []
#loop through each value in list
for value in l:
#append the value two times in resultant list
res.append(value)
res.append(value)
return res
print(echo(['a','b','c']))
print(echo(['x','y']))
print(echo([85,72,61]))
print(echo([85,"abc",6.79]))
Rules: You may NOT use the following built-in functions. sort() sum() max() min() Except for format()...
You may import the following library functions in your module: from fractions import gcd from math import floor from random import randint You may also use: • the built-in pow() function to compute modular exponents efficiently (i.e., ak mod n can be written in Python as pow(a,k,n)), • the sum() function returns the sum of a list of integers (sum(1,2,3,4) returns 10). problem 1 a. Implement a function invPrime(a, p) that takes two integers a and p > 1 where...
YOU NEED TO MODIFY THE PROJECT INCLUDED AT THE END AND USE THE INCLUDED DRIVER TO TEST YOUR CODE TO MAKE SURE IT WORK AS EXPECTED. Thanks USING PYTHON, complete the template below such that you will provide code to solve the following problem: Please write and/or extend the project5 attached at the end. You will have to do the following for this assignment: Create and complete the methods of the PriceException class. Create the processFile function. Modify the main...
IT PYTHON QUESTION1 Consider the following Python code, where infile.txt and outfile.txt both exist in the current directory 'z' ) 。1d = open ( ' infile. txt ' , for line in old: new.write (line) new.write') ne«.close () old.close) Which of the following options best describes the purpose or outcome of this code? O A copy of the file infile.txt is made (except in double line spacing) and saved as outfile.txt in the current directory. O A copy of the...
For this assignment, you will write a program to work with Huffman encoding. Huffman code is an optimal prefix code, which means no code is the prefix of another code. Most of the code is included. You will need to extend the code to complete three additional methods. In particular, code to actually build the Huffman tree is provided. It uses a data file containing the frequency of occurrence of characters. You will write the following three methods in the...
could you please help me with this problem, also I need a little text so I can understand how you solved the problem? import java.io.File; import java.util.Scanner; /** * This program lists the files in a directory specified by * the user. The user is asked to type in a directory name. * If the name entered by the user is not a directory, a * message is printed and the program ends. */ public class DirectoryList { public static...