**Programming, Data Structures And Algo Using Python Assignment 4 Answers 2023:-** In This article, we have provided the answers of Programming, Data Structures And Algo Using Python Assignment 4 You must submit your assignment to your own knowledge.

## Programming, Data Structures And Algorithms Using Python Week 4 Quiz Assignment Answers 2023

**1. Consider the following Python function.**

def mystery(l):

if l == []:

return(l)

else:

return(l[-1:]+mystery(l[:-1]))

**What does mystery([23,35,19,58,93,46]) return?**

Answer :-For AnswerClick Here

**2. Consider the following Python function.**def mystery(l):

if l == []:

return(l)

else:

return(l[-1:]+mystery(l[:-1]))

**What does mystery([23,35,19,58,93,46]) return?**

Answer :-For AnswerClick Here

**3. Consider the following dictionary.**goals = {“Country”:{“Ronaldo”:123,”Messi”:103,”Pele”:83},”Club”:{“Ronaldo”:[512,51,158],”Pele”:[604,49,26]}}

**Which of the following statements does not generate an error?**

goals[“Club”][“Messi”][0:] = [496,71,145]

goals[“Club”][“Messi”].extend([496,71,145])

goals[“Club”][“Messi”] = [496,71,145]

goals[“Club”][“Messi”] = goals[“Club”][“Messi”] + [496,71,145]

Answer :-For AnswerClick Here

**4. Assume that wickets has been initialized as an empty dictionary:**wickets = {}

**Which of the following generates an error?**

wickets[“Muralitharan, tests”] = 800

wickets[“Muralitharan”] = {“tests”:800}

wickets[(“Muralitharan”,”tests”)] = 800

wickets[[“Muralitharan”,”tests”]] = 800

Answer :-

## Programming, Data Structures And Algorithms Using Python Week 4 Programming Assignment Answers 2023

**1. Write a Python function histogram(l) that takes as input a list of integers with repetitions and returns a list of pairs as follows:.for each number n that appears in l, there should be exactly one pair (n,r) in the list returned by the function, where r is the number of repetitions of n in l.the final list should be sorted in ascending order by r, the number of repetitions. For numbers that occur with the same number of repetitions, arrange the pairs in ascending order of the value of the number.**

**For instance**

```
>>> histogram([13,12,11,13,14,13,7,7,13,14,12])
[(11, 1), (7, 2), (12, 2), (14, 2), (13, 4)]
>>> histogram([7,12,11,13,7,11,13,14,12])
[(14, 1), (7, 2), (11, 2), (12, 2), (13, 2)]
>>> histogram([13,7,12,7,11,13,14,13,7,11,13,14,12,14,14,7])
[(11, 2), (12, 2), (7, 4), (13, 4), (14, 4)]
```

Answer :-For AnswerClick Here

**2. A college maintains academic information about students in three separate lists**

- Course details: A list of pairs of form (coursecode,coursename), where both entries are strings. For instance,
- [ (“MA101″,”Calculus”),(“PH101″,”Mechanics”),(“HU101″,”English”) ]
- Student details: A list of pairs of form (rollnumber,name), where both entries are strings. For instance,
- [ (“UGM2018001″,”Rohit Grewal”),(“UGP2018132″,”Neha Talwar”) ]
- A list of triples of the form (rollnumber,coursecode,grade), where all entries are strings. For instance, [ (“UGM2018001”, “MA101”, “AB”), (“UGP2018132”, “PH101”, “B”), (“UGM2018001″, “PH101”, “B”) ]. You may assume that each roll number and course code in the grade list appears in the student details and course details, respectively.

Your task is to write a function transcript (coursedetails,studentdetails,grades) that takes these three lists as input and produces consolidated grades for each student. Each of the input lists may have its entries listed in arbitrary order. Each entry in the returned list should be a tuple of the form

(rollnumber, name,[(coursecode_1,coursename_1,grade_1),…,(coursecode_k,coursename_k,grade_k)])

where the student has grades for k ≥ 1 courses reported in the input list grades.

- The output list should be organized as follows.
- The tuples shold sorted in ascending order by rollnumber
- Each student’s grades should sorted in ascending order by coursecode

For instance

```
>>>transcript([("MA101","Calculus"),("PH101","Mechanics"),("HU101","English")],[("UGM2021001","Rohit Grewal"),("UGP2021132","Neha Talwar")],[("UGM2021001","MA101","AB"),("UGP2021132","PH101","B"),("UGM2021001","PH101","B")])
[('UGM2021001', 'Rohit Grewal', [('MA101', 'Calculus', 'AB'), ('PH101', 'Mechanics', 'B')]), ('UGP2021132', 'Neha Talwar', [('PH101', 'Mechanics', 'B')])]
>>>transcript([("T1","Test 1"),("T2","Test 2"),("T3","Test 3")],[("Captain","Rohit Sharma"),("Batsman","Virat Kohli"),("No3","Cheteshwar Pujara")],[("Batsman","T1","14"),("Captain","T1","33"),("No3","T1","30"),("Batsman","T2","55") ,("Captain","T2","158"),("No3","T2","19"), ("Batsman","T3","33"),("Captain","T3","95"),("No3","T3","51")])
[('Batsman', 'Virat Kohli', [('T1', 'Test 1', '14'), ('T2', 'Test 2', '55'), ('T3', 'Test 3', '33')]), ('Captain', 'Rohit Sharma', [('T1', 'Test 1', '33'), ('T2', 'Test 2', '158'), ('T3', 'Test 3', '95')]),('No3', 'Cheteshwar Pujara', [('T1', 'Test 1', '30'), ('T2', 'Test 2', '19'), ('T3', 'Test 3', '51')])]
```

Answer :-For AnswerClick Here

Course Name | Programming, Data Structures And Algorithms Using Python |

Category | NPTEL Assignment Answer |

Home | Click Here |

Join Us on Telegram | Click Here |

## Programming Data Structures And Algorithms Using Python Assignment 4 Quiz Answers [July 2022]

**Q1. Consider the following Python function.****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?**

Answer:- [(4,5), (4,2), (3,3), (2,4)]

**Q3. Consider the following dictionary.**

Which of the following statements does not generate an error?

Answer:-c. wickets["ODI"]["Ashwin"] = [4,4]

**Q4. Assume that hundreds has been initialized as an empty dictionary:**

Which of the following generates an error?

Answer:-d.hundreds[["Tendulkar","international"]] = 100

## Week 4 Programming Assignment

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.

Code:-

```
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)
```

## Programming Data Structures And Algorithms Using Python Assignment Answers [Jan 2022] Quiz Assignment

**Q1. Consider the following Python function.**

```
def mystery(l,v):
if len(l) == 0:
return (v)
else:
return (mystery(l[:-1],l[-1]+v))
```

What does mystery([22,14,19,65,82,55],1) return?

**Answer:- 258**

**👇FOR NEXT WEEK ASSIGNMENT ANSWERS👇**

**Q2. What is the value of triples after the following assignment?**

`triples = [ (x,y,z) for x in range(2,4) for y in range(2,5) for z in range(5,7) if 2*x*y > 3*z ]`

**Answer:- ****[(2,4,5),(3,3,5),(3,4,5),(3,4,6)]**

**Q3. Consider the following dictionary.**

runs = {"Test":{"Rahul":[90,14,35],"Kohli":[3,103,73,42],"Pujara":[53,15,133,8]},"ODI":{"Sharma":[37,99],"Kohli":[63,47]}}

**Answer:- d**

**Q4. Assume that actor has been initialized as an empty dictionary:**

`actor = {}`

**Answer:- c – actor[[“Star Wars”, “Rey”]] = “Ridley”**

## Programming Assignment:-

**Q1.**

We represent scores of batsmen across a sequence of matches in a two level dictionary as follows: Each match is identified by a string, as is each player. The scores are all integers. The names associated with the matches are not fixed (here they are ‘match1’, ‘match2’, ‘match3’), nor are the names of the players. A player need not have a score recorded in all matches.

Define a Python function orangecap(d) that reads a dictionary d of this form and identifies the player with the highest total score. Your function should return a pair (playername,topscore) where playername is a string, the name of the player with the highest score, and topscore is an integer, the total score of playername.

The input will be such that there are never any ties for highest total score.

**Code:-**

**code will be uploaded soon and will be notified on our telegram channel**

**👇FOR NEXT WEEK ASSIGNMENT ANSWERS👇**

**Disclaimer**:- We do not claim 100% surety of solutions, these solutions are based on our sole expertise, and by using posting these answers we are simply looking to help students as a reference, so we urge do your assignment on your own.

**For More NPTEL Answers:- CLICK HERE**

**Join Our Telegram:- CLICK HERE**

**Programming, Data Structures And Algo Using Python Assignment 4 Answers 2022:-** In This article, we have provided the answers of Programming, Data Structures And Algo Using Python Assignment 4 You must submit your assignment to your own knowledge.