NPTEL PROGRAMMING ASSIGNMENTS
Programming, Data Structures And Algorithms Using Python
Week 4 Programming Assignment
Last Day of Submission: 25-Aug-2022
1. Write a Python function frequency(l) that takes as input a list of integers and returns a pair of the form (minfreqlist, maxfreqlist) where
1. Write a Python function frequency(l) that takes as input a list of integers and returns a pair of the form (minfreqlist, maxfreqlist) where
minfreqlist is a list of numbers with minimum frequency in l, sorted in ascending order
maxfreqlist is a list of numbers with maximum frequency in l, sorted in ascending order
Input Function:
frequency([9,2,9,2,7,7,3,1,1,9])
Output:
Output:
([3], [9])
2. Write a Python function onehop(l) that takes as input a list of pairs representing direct flights and returns a list of all pairs (i, j), where i! =j, such that i and j are connected by one hop. Note that it may already be the case that there is a direct flight from i to j. So long as there is an intermediate k with a flight from i to k and from k to j, the list returned by the function should include (i, j). The input list may be in any order. The pairs in the output list should be in lexicographic (dictionary) order. Each pair should be listed exactly once.
Input Function:
onehop([(2,3),(1,2)])
Output: