Find the output of the following Python code: def CollectionsMagic(L, T, D):…
2026
Find the output of the following Python code:
def CollectionsMagic(L, T, D):
L.append(L[0] + L[1])
D[T] = min(T)
D['Total'] = sum(L)
print("Tuple:", T[::-1]) # Output 3A
print("List:", L) # Output 3B
print("Dict:", list(D.keys())) # Output 3C
L1 = [10, 20]
T1 = (5, 15, 25)
D1 = {'A': 1}
CollectionsMagic(L1, T1, D1)
print("Final:", len(L1) + len(D1)) # Output 3D
Show answer & explanation
In function
CollectionsMagic(L, T, D),L(list) andD(dictionary) are mutable, whileT(tuple) is immutable.L.append(L[0] + L[1])⇒[10, 20] → [10, 20, 30]D[T] = min(T)⇒ key(5, 15, 25)is added with value5D['Total'] = sum(L)⇒ sum =60, so dictionary becomes{'A':1, T1:5, 'Total':60}T[::-1]⇒ tuple is reversed to(25, 15, 5)Outputs inside function:
Tuple: (25, 15, 5)
List: [10, 20, 30]
Dict: ['A', (5, 15, 25), 'Total']
Final output:
len(L1)=3,len(D1)=3⇒ Final: 6