Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit

CS1010E: Programming Methodology

Assignment 4: Map, Filter, Search, Sort, OOP


Submission Instructions

Read ALL instructions carefully.

1. Submission Content:

Each question will be given a template file (e.g., aN_qM_template.py ).

You should work on your file locally before submitting it to Coursemology.

Comment out all the given test cases and import statements before copying the content of the entire file to Coursemology, replacing any content on Coursemology:

On template file: CTRL + A followed by CTRL + C  (i.e., copy all).

On Coursemology: CTRL + A followed by CTRL + V  (i.e., replace all).

If any implementation is given, you are not allowed to change them.

You are not allowed to add, remove, or modify any parameters from functions.

You are not allowed to change the name of the given function.

Unless otherwise stated, you are not allowed to add/change import.

This assignment contains 6 Questions, where Question 4 and Question 6 convey

1 CA mark each.

2. Finalizing Submissions:

You are responsible for finalizing your submission.

Late submission is not allowed

You should not submit at the last minute since Coursemology is not designed to handle a large workload.

If you see that Coursemology is under maintenance, it is due to the large workload and not actual maintenance. No extension will be given.

3. Testing:

Do not call the required functions when you copy the code to Coursemology as it will be called automatically during testing.

Your function should return the result instead of print.

Test cases are called in succession (i.e., no reverting of global state).

Passing all test cases (public or private) does not guarantee full marks as we will do a manual evaluation on other aspects such as code quality.

You may assume that the code will only be tested on valid inputs that follow theassumption. Do NOT put any checks for inputs with respect to the assumptions, UNLESS it is directly asked in the Question.

4. Good Programming Practice:

Codes that are redundant or too long may be penalized.

Restrictions must not be violated.

Each test case (public or private) should complete within a reasonable amount of time typically within 1s to 2s

Failure to follow any of the instructions above will result in a deduction of your marks.










Assignment  4:  Map, Filter, Search, Sort, OOP

** Attention: This assignment contains 6 Questions, where

Question 4 and Question 6 convey 1 CA mark each.

Deadline: 23-4-2022, 23:59


Question 1: Hash Keys (S&S)

Develop a program to get any input string and return a tuple of 2 hash keys computed for that string.

(hk1 , hk2) = hash_keys(instr)

def hash_ keys( instr ):


return (hk1,hk2,)

The first hash key would be computed by XORING all the characters of the input string instr. You need to find a way to get the code (ASCII or UNICODE) of each character.

The second hash key would be computed by multiplying characters of instr by          consecutive powers of 2, adding the results together, and computing the remainder of its division by 1024.


instr = ‘abcd

hk1 = a xor b xor c xor d

hk2 = (a*2**0 + b*2**1 + c*2**2 + d*2**3) % 1024


You need to find: a way to access the characters of a string, a function that

returns the ASCII/Unicode code of a character, and the XOR operator.

•        Check the test cases 1 to 3, (‘a’, ‘aA’, ‘Aa’). Why the hash keys are like that?

Add your answer as a comment at the end of your code before submitting.

Test Cases:

>>> hash_keys( 'a' )

(97, 97)

>>> hash_keys( 'aA' )

(32, 227)

>>> hash_keys( 'Aa' )

(32, 259)

# Why? What do you think? Add your