CBSE Class 12 Computer Science
Question 20 of 68
Data Structures - I : Linear Lists — Question 2
Back to all questions[('H', 1), ('E', 1), ('L',1), ('L',1), ('O', 1)]
Reason —
lst1 = "hello"— This line initializes a string variablelst1with the value "hello".lst2 = list((x.upper(), len(x)) for x in lst1)— This line is a list comprehension, which iterates over each characterxin the stringlst1. For each characterx, it creates a tuple containing two elements:
(a) The uppercase version of the characterx, obtained using theupper()method.
(b) The length of the characterx, obtained using thelen()function.
These tuples are collected into a list, which is assigned to the variablelst2.print(lst2)— This line prints the listlst2.