Programming Data Structure And Algorithms Using Python Assignment 4
Course Name: Programming Data Structure And Algorithms Using Python
Link of Course: Click Here
These are the solutions of Programming Data Structure And Algorithms Using Python Assignment 4
Q1) Consider the following Python function.
def mystery (1):
if 1 == [] :
return (1)
else :
return(mystery (1[1 : ])+1[1])
What does mystery ([22, 14, 19, 65, 82,55]) return?
Answer: [55, 82, 65, 19, 14, 22]
Q2) What is the value of pairs after the following assignment?
pairs = [ (x,y) for x in range (4,1,-1) for y in range (5,1,-1) if (x+y)%3 ==0]
Answer: [(4,5), (4,2), (3,3), (2,4)]
These are the solutions of Programming Data Structure And Algorithms Using Python Assignment 4
Q3) Consider the following dictionary.
wickets = {“Tests” : {“Bumrah” : [3,5,2,3], “Shami” : [4,4,1,0], “Ashwin” : [2,1,7,4]}, “ODI” : {“Bumrah” : [2, 0], “Shami” : [1,2]}}
Which of the following statements does not generate an error?
wickets [“ODI”][“Ashwin”][ : ] = [4,4]
wickets [“ODI”][“Ashwin”].extend ([4,4])
wickets [“ODI”][“Ashwin”] = [4,4]
wickets [“ODI”][“Ashwin”] = wickets [“ODI”][“Ashwin”] + [4,4]
Answer: wickets [“ODI”][“Ashwin”] = [4,4]
Q4) Assume that hundreds has been initialized as an empty dictionary :
hundreds = {}
Which of the following generates an error?
hundreds [“Tendulkar, international”] = 100
hundreds [“Tendulkar”] = {“international” : 100}
hundreds [(“Tendulkar”, “international”)] = 100
hundreds [[“Tendulkar”, “international”]] = 100
Answer: hundreds [[“Tendulkar”, “international”]] = 100
These are the solutions of Programming Data Structure And Algorithms Using Python Assignment 4
Programming Assignment Solution
Q1. Write two Python functions as specified below. Paste the text for both functions together into the submission window. Your function will be called automatically with various inputs and should return values as specified. Do not write commands to read any input or print any output.
Solution:
def frequency(l):
SET=set(l)
LIST=list(SET)
newl=list()
for a in LIST:
newl.append(l.count(a))
mi=min(newl)
ma=max(newl)
mil=[]
mal=[]
for b in range(len(newl)):
if newl[b]==mi:
mil.append(LIST[b])
if newl[b]==ma:
mal.append(LIST[b])
mil.sort()
mal.sort()
return(mil,mal)
def onehop(l):
ans=list()
l.sort()
for x in range(len(l)):
for y in range(len(l)):
if l[x]!=l[y]:
if l[x][1]==l[y][0]:
q=l[x][0]
w=l[y][1]
if q!=w:
t=[q,w]
t=tuple(t)
if t not in ans:
ans.append(tuple(t))
ans.sort()
return (ans)
These are the solutions of Programming Data Structure And Algorithms Using Python Assignment 4
All weeks solution of Programming Data Structure And Algorithms Using Python: https://progies.in/answers/nptel/programming-data-structure-and-algorithms-using-python
More NPTEL Solutions: https://progies.in/answers/nptel
* The material and content uploaded on this website are for general information and reference purposes only. Please do it by your own first. COPYING MATERIALS IS STRICTLY PROHIBITED.