0% found this document useful (0 votes)
84 views

Python jr-3

The document provides instructions for submitting coding questions and questions to be coded. The questions include: 1) Writing a function to find items that appear only once in a list, without using certain libraries. 2) Replacing each element of an array with the next greatest element to its right, or -1 if at the end. 3) Printing a specified pattern of numbers. 4) Returning a character encoded sequence for a given positive integer input. 5) Choosing a possible random output list with reason.

Uploaded by

Vaibhav Hiwase
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
84 views

Python jr-3

The document provides instructions for submitting coding questions and questions to be coded. The questions include: 1) Writing a function to find items that appear only once in a list, without using certain libraries. 2) Replacing each element of an array with the next greatest element to its right, or -1 if at the end. 3) Printing a specified pattern of numbers. 4) Returning a character encoded sequence for a given positive integer input. 5) Choosing a possible random output list with reason.

Uploaded by

Vaibhav Hiwase
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Instructions

1. Please upload the files on onedrive without zipping/compressing it in running state.


2. Each question should either have its own .py (python) file or if you are using a jupyter notebook/lab
please export it as html. Avoid “.ipynb” files.
3. It is not mandatory to comment the code.

Questions

1. Provided a non-empty list of items, write a function to find all items which appear only once.

Limitation: Use of collections, heapq and numpy is not allowed

Input: ['1', 'go', 'wait', 1, 'go', '1', 'wait', 'go', ‘hi’]


Output: 1
Explanation: The string '1' appears two times, 'go' appears three times, 'wait' appears two times but
integer item 1 and string ‘hi’ appears only once. This item is the odd one out.

Input: [(1, 2), (3, 4), {'a': 'b'}, 'fine', 1, {'a': 'b'}, (3, 4), 1, 'fine', 'fine']
Output: (1, 2)
Explanation : The tuple (1, 2) appears only once where as tuple (3, 4) appears two times, the
dictionary appears two times, integer 1 appears two times, string 'fine' appears three times. The tuple
(1, 2) is the odd one out.

Input: [[]]
Output - []
Explanation: As the input list only contains one item which is another vacant list, this would be the
item with single occurrence. So the output is the vacant list item.

2. Given an array, replace every element with the next greatest element (greatest element on its right
side) in the array. Also, since there is no element next to the last element, replace it with -1.

Input: [ 16, 17, 4, 3, 5, 2 ]


Output: [17, 5, 5, 5, 2, -1 ]

Input: [2, 3, 1, 9]
Output: [9, 9, 9, -1]

3. Print the following pattern

Input: 4
Output:

1 2 3 4 17 18 19 20
5 6 7 14 15 16
8 9 12 13
10 11
Input: 3
Output:

1 2 3 10 11 12
4589
67

4. Provided a positive integer as a parameter, write a function which returns a counting character
encoded sequence of the input integer.

Input: 1
output: 11
Explanation: Input has only one 1. We get 11 (Read as “one 1”) as output

input: 211
output : 1221
Explanation: Input has only one 2 and two 1s. Hence we get 1221 ( Read as “one 2 and two 1s” ) as
output

input: 1221
output: 112211
Explanation: Input has one 1, two 2s and one 1 again. Hence we get 112211 as output.

5. Choose a possible output with reason

from random import randrange


L = list()
for x in range(5):
L.append(randrange(0, 100, 2)-10)
print(L)

a) [-8, 88, 8, 58, 0]


b) [-8, 81, 18, 46, 0]
c) [-7, 88, 8, 58, 0]
d) [-8, 88, 94, 58, 0]

You might also like