Assignment 3

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 23

Department of Artificial Intelligence and Data Science

Academic Year: 2022-2023 (Odd Semester)


Assignment 3
Degree & Branch: B.Tech - ARTFICIAL INTELLIGENCE AND DATA SCIENCE
Year/Semester/Section: I/ I /A
Regulation: Anna University R 2021
Course Code & Title: GE3151 Problem Solving and Python Programming

S.N Roll
Name of the Student Problem
O Number
Given a list, write a Python program
to swap first and last element of the
list.
Examples:
1. 22AD001 AKILAN A Input : [12, 35, 9, 56, 24]
Output : [24, 35, 9, 56, 12]

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

Given a list in Python and provided


the positions of the elements, write
a program to swap the two elements
in the list.

Examples:
2. 22AD002 AKSHAYA S Input : List = [23, 65, 19, 90], pos1 =
1, pos2 = 3
Output : [19, 65, 23, 90]

Input : List = [1, 2, 3, 4, 5], pos1 = 2,


pos2 = 5
Output : [1, 5, 3, 4, 2]

3. 22AD003 AKSHAYANIVASINI M Given a list of numbers, write a


Python program to print all even
numbers in the given list.
Example:
Input: list1 = [2, 7, 5, 64, 14]
Output: [2, 64, 14]

Input: list2 = [12, 14, 95, 3]


Output: [12, 14]

Given a string. the task is to check if


the string is symmetrical and
palindrome or not. A string is said to
be symmetrical if both the halves of
the string are the same and a string
is said to be a palindrome string if
one half of the string is the reverse
of the other half or if a string
appears same when read forward or
backward.

4. 22AD004 ANBARASAN C Example:


Input: khokho
Output:
The entered string is symmetrical
The entered string is not
palindrome

Input:amaama
Output:
The entered string is symmetrical
The entered string is palindrome

We are given a string and we need


to reverse words of a given string
Examples:
Input : str =" geeks quiz practice
code"
5. 22AD005 BALAVIGNESH M
Output : str = code practice quiz
geeks

Input : str = "my name is laxmi"


output : str= laxmi is name my

6. 22AD006 BHUVANEHSWARI G we will need to accept a string and


we need to check if the string
contains any URL in it. If the URL is
present in the string, we will say
URL’s been found or not and print
the respective URL present in the
string. We will use the concept of
Regular Expression of Python to
solve the problem.
Examples:
Input : string = 'I am a blogger at
https://geeksforgeeks.org'
Output : URL :
['https://geeksforgeeks.org']

A permutation, also called an


“arrangement number” or “order”, is
a rearrangement of the elements of
an ordered list S into a one-to-one
correspondence with S itself. A
string of length n has n!
permutation.
Examples:
Input : str = 'ABC'
7. 22AD007 CHITRAKALA J Output :
ABC
ACB
BAC
BCA
CAB
CBA

8. 22AD008 DEEPIKAA E Given two sentences as


strings A and B. The task is to return
a list of all uncommon words. A
word is uncommon if it
appears exactly once in any one of
the sentences, and does not appear
in the other sentence. Note: A
sentence is a string of space-
separated words. Each word
consists only of lowercase letters.
Examples:
Input : A = “apple banana mango” ,
B = “banana fruits mango”
Output : [‘apple’, ‘fruits’]
Given the string, the task is to
generate the same string using the
random combination of special
character, numbers, and alphabets.
Examples :
Input : GFG
Output :
n4W
mK7
k1x
q;;, !g
.
9. 22AD009 DEVA SAHAYARAJ A
.
.
.
.
GF,
GFf
GFp
GFG

Target matched after 167 iterations

Given string str. The task is to check


whether it is a binary string or not.
Examples:
Input: str = "01010101010"
Output: Yes
10. 22AD010 DHANESH KUMAR P

Input: str = "apple101"


Output: No

11. 22AD011 DHARUSHYAN N Given a list of integers with


duplicate elements in it. The task is
to generate another list, which
contains only the duplicate
elements. In simple words, the new
list should contain elements that
appear as more than one.
Examples:
Input : list = [10, 20, 30, 20, 20, 30,
40, 50, -20, 60, 60, -20, -20]
Output : output_list = [20, 30, -20,
60]
Input : list = [-1, 1, -1, 8]
Output : output_list = [-1]

Our task is to print the element


which occurs 3 consecutive times in
a Python list.
Example :
Input : [4, 5, 5, 5, 3, 8]

12. 22AD012 DIVYALAKSHMI K Output : 5

Input : [1, 1, 1, 64, 23, 64, 22, 22,


22]

Output : 1, 22

Given an array arr[] of N positive


integers. The task is to find the
maximum for every adjacent pair in
the array.
Examples:
13. 22AD013 GANESH ARAVIND A Input: 1 2 2 3 4 5
Output: 2 2 3 4 5

Input: 5 5
Output: 5

14. 22AD014 GOWTHAMAN S Sometimes, while working with


Python records, we can have a
problem in which we need to
remove records on the basis of
presence of consecutive K elements
in tuple. This kind of problem is
peculiar but can have applications in
data domains. Let’s discuss certain
ways in which this task can be
performed.
Input :
test_list = [(4, 5), (5, 6), (1, 3), (0, 0)]
K=0
Output : [(4, 5), (5, 6), (1, 3)]
Input :
test_list = [(4, 5), (5, 6), (1, 3), (5, 4)]
K=5
Output : [(4, 5), (5, 6), (1, 3), (5, 4)]

The combination is a mathematical


technique which calculates the
number of possible arrangements in
a collection of items or list. In
combination order of selection
doesn’t matter. The unique
combination of two lists in Python
can be formed by pairing each
element of the first list with the
15. 22AD015 HARI KRISHNAN A
elements of the second list.
Example:
List_1 = ["a","b"]
List_2 = [1,2]
Unique_combination = [[('a',1),
('b',2)],[('a',2),('b',1)]]

Sometimes, while working with


Python tuples list, we can have a
problem in which we need to
perform retention of all the records
where occurrences of K is N times.
This kind of problem can come in
domains such as web development
16. 22AD016 HARIS KANTHAKUMAR K M and day-day programming.
Input : test_list = [(4, 5, 5, 4), (5, 4,
3)], K = 5, N = 2
Output : [(4, 5, 5, 4)]
Input : test_list = [(4, 5, 5, 4), (5, 4,
3)], K = 5, N = 3
Output : []

17. 22AD017 HARSHINI S.G Given a list, the task is to sort the
list according to the column using
the lambda approach.
Examples:
Input :
array = [[1, 3, 3], [2, 1, 2], [3, 2, 1]]
Output :
Sorted array specific to column 0,
[[1, 3, 3], [2, 1, 2], [3, 2, 1]]
Sorted array specific to column 1,
[[2, 1, 2], [3, 2, 1], [1, 3, 3]]
Sorted array specific to column 2,
[[3, 2, 1], [2, 1, 2], [1, 3, 3]]
Input :
array = [[‘java’, 1995], [‘c++’, 1983],
[‘python’, 1989]]
Output :
Sorted array specific to column 0,
[[‘c++’, 1983], [‘java’, 1995],
[‘python’, 1989]]
Sorted array specific to column 1,
[[‘c++’, 1983], [‘python’, 1989],
[‘java’, 1995]]

Given two lists, extract all elements


from the first list, whose
corresponding index in the second
list contains the required substring.
Examples:
Input : test_list1 = [“Gfg”, “is”, “not”,
“best”, “and”, “not”, “CS”],
test_list2 = [“Its ok”, “all ok”,
“wrong”, “looks ok”, “ok”, “wrong”,
“thats ok”], sub_str = “ok”
Output : [‘Gfg’, ‘is’, ‘best’, ‘and’, ‘CS’]
Explanation : All retained contain
18. 22AD018 HIRTHIK RAJ A “ok” as substring in corresponding
idx, e.g : Gfg -> Its ok ( has ok ) as
substr.
Input : test_list1 = [“Gfg”, “not”,
“best”],
test_list2 = [“yes”, “noo”, “its yes”],
sub_str = “yes”
Output : [‘Gfg’, ‘best’]
Explanation : All retained contain
“yes” as substring in corresponding
idx, e.g : Gfg -> yes ( has yes ) as
substr.
Given a List. The task is to replace
all the characters of the list with N
except the given character.
Input : test_list = [‘G’, ‘F’, ‘G’, ‘I’, ‘S’,
‘B’, ‘E’, ‘S’, ‘T’], repl_chr = ‘*’, ret_chr
= ‘G’
Output : [‘G’, ‘*’, ‘G’, ‘*’, ‘*’, ‘*’, ‘*’, ‘*’,
19. 22AD019 ILAKKIYAN G ‘*’]
Explanation : All characters except
G replaced by *
Input : test_list = [‘G’, ‘F’, ‘G’, ‘B’, ‘E’,
‘S’, ‘T’], repl_chr = ‘*’, ret_chr = ‘G’
Output : [‘G’, ‘*’, ‘G’, ‘*’, ‘*’, ‘*’, ‘*’]
Explanation : All characters except
G replaced by *

Given list of Strings, task is to


remove all the strings, which are
substrings of other Strings.
Input : test_list = [“Gfg”, “Gfg is
best”, “Good”, “for”, “Gfg is for
20. 22AD020 JAGADIISH S D Good”]
Output : [‘Gfg is best’, ‘Gfg is for
Geeks’]
Explanation : “Gfg”, “for” and
“Good” are present as substrings in
other strings.

Given a Tuple List, perform sort on


basis of total digits in tuple.
Examples:
Input : test_list = [(3, 4, 6, 723), (1,
2), (134, 234, 34)]
Output : [(1, 2), (3, 4, 6, 723), (134,
234, 34)]
21. 22AD021 JAYARAJ V Explanation : 2 < 6 < 8, sorted by
increasing total digits.

Input : test_list = [(1, 2), (134, 234,


34)]
Output : [(1, 2), (134, 234, 34)]
Explanation : 2 < 8, sorted by
increasing total digits.

22. 22AD022 JEEVA SHRI A Sometimes, while working with


Python tuples data, we can have a
problem in which we need to extract
all possible combination of 2
argument tuples. This kind of
application can come in Data
Science or gaming domains.
Input : test_tuple1 = (7, 2),
test_tuple2 = (7, 8)
Output : [(7, 7), (7, 8), (2, 7), (2, 8),
(7, 7), (7, 2), (8, 7), (8, 2)]
Input : test_tuple1 = (9, 2),
test_tuple2 = (7, 8)
Output : [(9, 7), (9, 8), (2, 7), (2, 8),
(7, 9), (7, 2), (8, 9), (8, 2)]

Given a list of tuples. The task is to


extract all tuples which have all
elements divisible by K.
Input : test_list = [(6, 24, 12), (60,
12, 6), (12, 18, 21)], K = 6
Output : [(6, 24, 12), (60, 12, 6)]
23. 22AD023 KABILA T Explanation : Both tuples have all
elements multiple of 6.
Input : test_list = [(6, 24, 12), (60,
10, 5), (12, 18, 21)], K = 5
Output : [(60, 10, 5)]
Explanation : Multiple of 5 tuples
extracted.

Given a list of tuples. The task is to


get all the tuples that have all
positive elements.
Examples:
Input : test_list = [(4, 5, 9), (-3, 2, 3),
(-3, 5, 6), (4, -6)]
Output : [(4, 5, 9)]

24. 22AD024 KALEESWARI G Explanation : Extracted tuples with


all positive elements.
Input : test_list = [(-4, 5, 9), (-3, 2, 3),
(-3, 5, 6), (4, -6)]
Output : []
Explanation : No tuple with all
positive elements.
Sometimes, while working with
Python lists, we can have a problem
in which we need to perform
extraction of all the digits from tuple
list. This kind of problem can find its
application in data domains and
25. 22AD025 KARTHIKEYAN M day-day programming.
Input : test_list = [(15, 3), (3, 9)]
Output : [9, 5, 3, 1]
Input : test_list = [(15, 3)]
Output : [5, 3, 1]

Given a list of tuples, write a Python


program to sort the tuples
alphabetically by the first item of
each tuple.
Examples:
Input: [("Amana", 28), ("Zenat", 30),
("Abhishek", 29), ("Nikhil", 21), ("B",
"C")]
26. 22AD026 KAVYA SHREE S Output: [('Amana', 28), ('Abhishek',
29), ('B', 'C'), ('Nikhil', 21), ('Zenat',
30)]

Input: [("aaaa", 28), ("aa", 30),


("bab", 29), ("bb", 21), ("csa", "C")]
Output: [('aa', 30), ('aaaa', 28),
('bab', 29), ('bb', 21), ('csa', 'C')]

Sometimes, while working with


Python list, we can have a task in
which we need to work with tuple
list and get the product of it’s Kth
index. This problem has application
in web development domain while
27. 22AD027 LAKSHMI PRIYA K working with data informations.
The original list is : [(5, 6, 7), (1, 3,
5), (8, 9, 19)]
Product of Kth Column of Tuple
List : 665

28. 22AD028 MAHALAKSHMI M Sometimes, while working with


Python Tuples, we can have a
problem in which we need to
perform the flattening of tuples,
which have lists as its constituent
elements. This kind of problem is
common in data domains such as
Machine Learning.
Input : test_tuple = ([5], [6], [3],
[8])
Output : (5, 6, 3, 8)
Input : test_tuple = ([5, 7, 8])
Output : (5, 7, 8)

Given a Tuple Matrix, flatten to


tuple list with each tuple
representing each column.
Input : test_list = [[(4, 5), (7, 8)],
29. 22AD029 MANOJ KUMAR M [(10, 13), (18, 17)]]
Output : [(4, 7, 10, 18), (5, 8, 13,
17)]
Explanation : All column number
elements contained together.

Sometimes, while working with


Python Matrix, we can have a
problem in which we need to
perform conversion of a Python
Matrix to matrix of tuples which a
value attached row-wise custom
from external list. This kind of
problem can have application in
data domains as Matrix is integral
30. 22AD030 MOHAMED SUHAIL R DS that is used.
Input : test_list = [[4, 5], [7, 3]],
add_list = [‘Gfg’, ‘best’]
Output : [(‘Gfg’, 4), (‘Gfg’, 5), (‘best’,
7), (‘best’, 3)]
Input : test_list = [[4, 5]], add_list =
[‘Gfg’]
Output : [(‘Gfg’, 4), (‘Gfg’, 5)]

31. 22AD031 MOHAMED THOUFIQ K Given an unsorted list of some


elements(may or may not be
integers), Find the frequency of each
distinct element in the list using a
dictionary.
Example:

Input : [1, 1, 1, 5, 5, 3, 1, 3, 3, 1,
4, 4, 4, 2, 2, 2, 2]
Output : 1 : 5
2:4
3:3
4:3
5:2
Explanation : Here 1 occurs 5 times,
2
occurs 4 times and so on...

Sometimes, while working with


Python dictionaries, we can have a
problem in which we need to
remove all the duplicate values
across all the dictionary value lists.
This problem can have applications
in data domains and web
development domains.
32. 22AD032 MOHANA VELU P
Input: test_dict = {‘Manjeet’: [1],
‘Akash’: [1, 8, 9]}
Output: {‘Manjeet’: [], ‘Akash’: [8,
9]}
Input: test_dict = {‘Manjeet’: [1, 1,
1], ‘Akash’: [1, 1, 1]}
Output: {‘Manjeet’: [], ‘Akash’: []}

Sometimes, while working with


Python dictionaries, we can have a
problem in which we need to
convert nested dictionaries to
mapped tuple. This kind of problem
can occur in web development and
day-day programming.
33. 22AD033 R MUTHU GURU GOWSALYA
Input : test_dict = {‘gfg’ : {‘x’ : 5, ‘y’ :
6, ‘z’: 3}, ‘best’ : {‘x’ : 8, ‘y’ : 3, ‘z’:
5}} Output : [(‘x’, (5, 8)), (‘y’, (6, 3)),
(‘z’, (3, 5))] Input : test_dict = {‘gfg’ :
{‘x’ : 5, ‘y’ : 6, ‘z’: 3}} Output : [(‘x’,
(5, )), (‘y’, (6, )), (‘z’, (3, ))]

34. 22AD034 NANDHA M Given a string which contains lower


alphabetic characters, we need to
remove at most one character from
this string in such a way that
frequency of each distinct character
becomes same in the string.
Examples:
Input : str = “xyyz”
Output : Yes
We can remove character ’y’ from
above
string to make the frequency of each
character same.

Input : str = “xyyzz”


Output : Yes
We can remove character ‘x’ from
above
string to make the frequency of each
character same.

Input : str = “xxxxyyzz”


Output : No
It is not possible to make frequency
of
each character same just by
removing at
most one character from above
string.

35. 22AD035 NITHIN R Given a dictionary and a character


array, print all valid words that are
possible using characters from the
array. Note: Repetitions of
characters is not allowed. Examples:
Input :
Dict =
["go","bat","me","eat","goal","boy",
"run"]
arr = ['e','o','b', 'a','m','g', 'l']
Output : go, me, goal.

Given a dictionary with nested


dictionaries as values, extract all the
values with of particular key.
Input : test_dict = {‘Gfg’ : {“a” : 7, “b”
: 9, “c” : 12}, ‘is’ : {“a” : 15, “b” : 19,
“c” : 20}, ‘best’ :{“a” : 5, “b” : 10, “c” :
2}}, temp = “b”
Output : [9, 10, 19]
36. 22AD036 PRADEEPA R Explanation : All values of “b” key
are extracted.
Input : test_dict = {‘Gfg’ : {“a” : 7, “b”
: 9, “c” : 12}, ‘is’ : {“a” : 15, “b” : 19,
“c” : 20}, ‘best’ :{“a” : 5, “b” : 10, “c” :
2}}, temp = “a”
Output : [7, 15, 5]
Explanation : All values of “a” key
are extracted.

Given two strings, find if we can


make first string from second by
deleting some characters from
second and rearranging remaining
characters.
Examples:
Input : s1 = ABHISHEKsinGH
: s2 =
37. 22AD037 PRAVEEN K
gfhfBHkooIHnfndSHEKsiAnG
Output : Possible

Input : s1 = Hello
: s2 = dnaKfhelddf
Output : Not Possible
38. 22AD038 RAGUNATH M Sometimes, while working with
Python records, we can have a
problem in which we need to find
the tuple nearest to certain tuple,
query on a particular index. This
kind of problem can have
application in data domains such as
web development.
Input :
test_list = [(3, 4), (78, 76), (2, 3), (9,
8), (19, 23)]
tup = (17, 23)
K=2
Output : (19, 23)
Input :
test_list = [(3, 4, 9), (5, 6, 7)]
tup = (1, 2, 5)
K=3
Output : (5, 6, 7)

Given a Tuple, nesting at 2nd


position, return summation of 1st
elements.
Input : test_tup = (5, (6, (1, (9,
None))))
39. 22AD039 RAJADHARSINI J Output : 21
Explanation : 9 + 6 + 5 + 1 = 21.
Input : test_tup = (5, (6, (1, None)))
Output : 12
Explanation : 1 + 6 + 5 = 12.

Given a sentence containing n


words/strings. Remove all
duplicates words/strings which are
similar to each others.
40. 22AD040 RATCHITA B Examples:
Input : Good for Good
Output : Good for

Given Binary Tuple representing


binary representation of a number,
convert to integer.
Input : test_tup = (1, 1, 0)
Output : 6
41. 22AD041 SAKTHI PRIYA M Explanation : 4 + 2 = 6.
Input : test_tup = (1, 1, 1)
Output : 7
Explanation : 4 + 2 + 1 = 7.
Given tuple list, extract the
frequency of unique tuples in list
order irrespective.
Input : test_list = [(3, 4), (1, 2), (4,
3), (3, 4)]
Output : 2
Explanation : (3, 4), (4, 3), (3, 4)
42. 22AD042 SAMSAN D makes 1 and (1, 2) is 2nd unique
element.
Input : test_list = [(3, 7), (1, 2), (4,
3), (5, 6)]
Output : 4
Explanation : All are different in
any order.

Given a Dictionary, divide dictionary


into K sized different dictionaries
list.
Input : test_dict = {‘Gfg’ : 1, ‘is’ : 2,
‘best’ : 3, ‘for’ : 4, ‘geeks’ : 5, ‘CS’ : 6},
K=3
Output : [{‘Gfg’: 1, ‘is’: 2, ‘best’: 3},
{‘for’: 4, ‘geeks’: 5, ‘CS’: 6}]
43. 22AD043 SANDHIYA S Explanation : Divided into size of 3
keys.
Input : test_dict = {‘Gfg’ : 1, ‘is’ : 2,
‘best’ : 3, ‘for’ : 4}, K = 2
Output : [{‘Gfg’: 1, ‘is’: 2}, {‘best’: 3,
‘for’: 4}]
Explanation : Divided into size of 2
keys.

44. 22AD044 SANJEEVI RAM R Sometimes, while working with


Python data, we can have problem
in which we need to convert the list
of dictionaries into list of lists, this
can be simplified by appending the
keys just once if they are repetitive
as mostly in records, this saves
memory space. This type of problem
can have applications in web
development domain.
Input : test_list = [{‘Gfg’: 123, ‘best’:
10}, {‘Gfg’: 51, ‘best’: 7}]
Output : [[‘Gfg’, ‘best’], [123, 10],
[51, 7]]
Input : test_list = [{‘Gfg’ : 12}]
Output : [[‘Gfg’], [12]]

Sometimes, while working with


Python dictionaries, we can have a
problem in which we need to filter
out certain values based on certain
conditions on a particular type, e.g
all values smaller than K. This task
becomes complex when dictionary
45. 22AD045 SHEIK MOHAMED ALI S values can be heterogeneous. This
kind of problem can have
applications across many domains.
Input : test_dict = {‘Gfg’ : 10, ‘for’ :
‘good’}
Output : {‘Gfg’: 10, ‘for’: ‘good’}

Given two numbers you are


required to check whether they are
anagrams of each other or not in
binary representation.
Examples:
Input : a = 8, b = 4
Output : Yes
46. 22AD046 SHENBAGA GANESHAN S
Binary representations of both
numbers have same 0s and 1s.

Input : a = 4, b = 5
Output : No

47. 22AD047 SHIFANA S Given a dictionary, perform append


of keys followed by values in list.
Input : test_dict = {“Gfg” : 1, “is” : 2,
“Best” : 3}
Output : [‘Gfg’, ‘is’, ‘Best’, 1, 2, 3]
Explanation : All the keys before all
the values in list.
Input : test_dict = {“Gfg” : 1, “Best” :
3}
Output : [‘Gfg’, ‘Best’, 1, 3]
Explanation : All the keys before all
the values in list.
Give a dictionary with value lists,
sort the keys by summation of
values in value list.
Input : test_dict = {‘Gfg’ : [6, 7, 4],
‘best’ : [7, 6, 5]}
Output : {‘Gfg’: 17, ‘best’: 18}
48. 22AD048 SIDDHARTH N.R Explanation : Sorted by sum, and
replaced.
Input : test_dict = {‘Gfg’ : [8], ‘best’ :
[5]}
Output : {‘best’: 5, ‘Gfg’: 8}
Explanation : Sorted by sum, and
replaced.

Sometimes, while working with


Python records, we can have a
problem in which we need to
resolve scoring in Python Matrix
records. This means mapping of
each key of dictionary with its value
to aggregate score of each row. This
kind of problem can have
49. 22AD049 SIVABALAN G applications in gaming and web
development domains.
Input : test_list = [[‘gfg’, ‘best’],
[‘goods’], [‘is’, ‘for’]]
Output : [18, 15, 12]
Input : test_list = [[‘gfg’, ‘goods’,
‘CS’]]
Output : [20]

50. 22AD050 SIVANI S Sometimes, while working with


Python records, we can have data
that come without proper column
names/identifiers, which can just be
identified by their index, but we
intend to assign them keys and
render in form of dictionaries. This
kind of problem can have
application in domains such as web
development.
Input : test_tuple = ((1, ‘Gfg’, 2), (3,
‘best’, 4)), keys = [‘key’, ‘value’, ‘id’]
Output : [{‘key’: 1, ‘value’: ‘Gfg’, ‘id’:
2}, {‘key’: 3, ‘value’: ‘best’, ‘id’: 4}]
Input : test_tuple = test_tuple = ((1,
‘Gfg’), (2, 3)), keys = [‘key’, ‘value’]
Output : [{‘key’: 1, ‘value’: ‘Gfg’},
{‘key’: 2, ‘value’: 3}]

Given an integer N, the task is to


find the number of groups having
the largest size. Each number from 1
to N is grouped according to
the sum of its digits.
Examples:
Input: N = 13
Output: 4
Explanation:
There are 9 groups in total, they are
grouped according to the sum of its
51. 22AD051 SRIRANJANI M digits of numbers from 1 to 13: [1,
10] [2, 11] [3, 12] [4, 13] [5] [6] [7]
[8] [9].
Out of these, 4 groups have the
largest size that is 2.
Input: n = 2
Output: 2
Explanation:
There are 2 groups in total. [1] [2]
and both the groups have largest
size 1.

52. 22AD052 STEPHANO I Given an array of n string containing


lowercase letters. Find the size of
largest subset of string which are
anagram of each others. An anagram
of a string is another string that
contains same characters, only the
order of characters can be different.
For example, “abcd” and “dabc” are
anagram of each other.
Examples:
Input:
ant magenta magnate tan gnamate
Output: 3
Explanation
Anagram strings(1) - ant, tan
Anagram strings(2) - magenta,
magnate,
gnamate
Thus, only second subset have
largest
size i.e., 3

Input:
cars bikes arcs steer
Output: 2

Given list of tuples, sort by


frequency of second element of
tuple.
Input : test_list = [(6, 5), (1, 7), (2,
5), (8, 7), (9, 8), (3, 7)]
Output : [(1, 7), (8, 7), (3, 7), (6, 5),
(2, 5), (9, 8)]
Explanation : 7 occurs 3 times as
53. 22AD053 SUJITHA M 2nd element, hence all tuples with 7,
are aligned first.
Input : test_list = [(1, 7), (8, 7), (9,
8), (3, 7)]
Output : [(1, 7), (8, 7), (3, 7), (9, 8)]
Explanation : 7 occurs 3 times as
2nd element, hence all tuples with 7,
are aligned first.

54. 22AD054 SWETHA R Sometimes, while working with


Python dictionaries, we can have a
problem in which we need to
remove keys whose values have
substring as argument we pass. This
problem can occur in cases of web
development and day-day
programming.
Input :
test_dict = {1 : ‘Gfg is best for
goods’}
sub_list = [‘love’, ‘good’] ( Strings to
check in values )
Output : {1: ‘Gfg is best for goods’}
Input :
test_dict = {1 : ‘Gfg is love’, 2: ‘Gfg is
good’}
sub_list = [‘love’, ‘good’] ( Strings to
check in values )
Output : {}

Given a list of tuples, filter by Kth


element presence in List.
Input : test_list = [(“GFg”, 5, 9), (“is”,
4, 3), (“best”, 10, 29)], check_list =
[4, 2, 3, 10], K = 2
Output : [(‘is’, 4, 3)]
Explanation : 3 is 2nd element and
55. 22AD055 THAMIZH SELVAN G present in list, hence filtered tuple.
Input : test_list = [(“GFg”, 5, 9), (“is”,
4, 3), (“best”, 10, 29)], check_list =
[4, 2, 3, 10], K = 1
Output : [(‘is’, 4, 3), (‘best’, 10, 29)]
Explanation : 4 and 10 are 1st
elements and present in list, hence
filtered tuples.

Given a dictionary with key-value


pairs, remove all the keys with
values greater than K, including
mixed values.
Input : test_dict = {‘Gfg’ : 3, ‘is’ : 7,
‘best’ : 10, ‘for’ : 6, ‘geeks’ : ‘CS’}, K =
7
Output : {‘Gfg’ : 3, ‘for’ : 6, ‘geeks’ :
‘CS’}
56. 22AD056 THANGAMAHESWARAN V Explanation : All values greater
than K are removed. Mixed value is
retained.
Input : test_dict = {‘Gfg’ : 3, ‘is’ : 7,
‘best’ : 10, ‘for’ : 6, ‘goods’ : ‘CS’}, K =
1
Output : {‘goods’ : ‘CS’}
Explanation : Only Mixed value is
retained.

57. 22AD057 VARUN SANKAR L Sometimes, while working with


Python dictionaries, we can have
problem in which we need to reform
the dictionary, in the form in which
all the values point to the keys that
they belong to. This kind of problem
can occur in many domains
including web development and
data domains.
Input : test_dict = {‘abc’ : [10, 30],
‘bcd’ : [30, 40, 10]}
Output : {10: [‘abc’, ‘bcd’], 30: [‘abc’,
‘bcd’], 40: [‘bcd’]}
Input : test_dict = {‘gfg’ : [1, 2, 3], ‘is’
: [1, 4], ‘best’ : [4, 2]}
Output : {1: [‘is’, ‘gfg’], 2: [‘gfg’,
‘best’], 3: [‘gfg’], 4: [‘is’, ‘best’]}

Given a Tuple List sort tuples by


maximum element in a tuple.
Input : test_list = [(4, 5, 5, 7), (1, 3,
7, 4), (19, 4, 5, 3), (1, 2)]
Output : [(19, 4, 5, 3), (4, 5, 5, 7), (1,
3, 7, 4), (1, 2)]
Explanation : 19 > 7 = 7 > 2, is
order, hence reverse sorted by
58. 22AD058 VEERAPUTHIRAKUMAR V maximum element.
Input : test_list = [(4, 5, 5, 7), (19, 4,
5, 3), (1, 2)]
Output : [(19, 4, 5, 3), (4, 5, 5, 7), (1,
2)]
Explanation : 19 > 7 > 2, is order,
hence reverse sorted by maximum
element.

Given a list with elements, construct


a dictionary with frequency of
factors.
Input : test_list = [2, 4, 6, 8]
Output : {1: 4, 2: 4, 3: 1, 4: 2, 5: 0, 6:
1, 7: 0, 8: 1}
59. 22AD059 VIDHYA V Explanation : All factors count
mapped, e.g 2 is divisible by all 4
values, hence mapped with 4.
Input : test_list = [1, 2]
Output : {1: 2, 2 : 1}
Explanation : Similar as above, 1 is
factor of all.

60. 22AD060 YOKESH RAM K Given an array of words, print all


anagrams together.
Examples:
Input: arr = [‘cat’, ‘dog’, ‘tac’, ‘god’,
‘act’]
Output: ‘cat tac act dog god’

You might also like