TUPLE

Welcome to TUPLE

How will you find out count of tuples occurrence in list of tuples? which option will you give correct result?Input = [[('a', 'c')],[('a', 'b')], [('a', 'b')]]
How will you sort a list of tuples by first Item?Input : [('45', 10), ('25', 5)]
Output : [('25', 5), ('45', 10)]
How to sort a list of tuples alphabetically?Input: [("aaaa", 2), ("aa", 3), ("bab", 9)]
Output: [('aa', 3), ('aaaa', 2), ('bab', 9)]
Find out count of tuples occurrence in list of tuplesimport collections
Output = collections.defaultdict(int)
Input = [[('a', 'c')],[('a', 'b')], [('a', 'b')]]
for elem in Input:
Output[elem[0]] += 1
print(Output)
John has bought 5 products. we have a list which contains product name and its price. Create one tuple which is sorted based on price.lst = [('Key', 101), ('Lock', 320), ('Hammer', 100), ('Spanner', 67), ('wire', 93)]

import operator
print(sorted(lst, reverse = True, key = operator.itemgetter(1)))

will it give the correct result?
Write a program to remove empty tuple from a list of tuples.lst1= [(), ('vikas', 5), ('mohan', 11), (), ('Harsha', 115),()]

lst2 = []

for item in lst1:

  if len(item) != 0:

     lst2.append(item)

print(lst2)

Write a program to create following 2 lists: - a list of names - a list of roll numbersGenerate and print a list of tuples containing name, roll number from the 2 lists. From this list generate 2 tuples—one containing all names, another containing all roll numbers.

name = ['vikas', 'Mohan', 'Aditya']

rollno = ['12', '42', '40']

Author: CloudVikas