Question: Assume tpl to be a tuple containing elements of different types ( int , string, float and bool ) . Write some code that counts
Assume tpl to be a tuple containing elements of different types int string, float and bool Write some code that counts how many elements have the same type as the first element. Store the result in a variable called count. Do not use a for loop.
Hint: You can use the type function to get the type of a value. The type function was introduced in Chapter
I did this and it doesn't work:
tpl a True
firstelement tpl
count
for index in range lentpl:
if typetplindex typefirstelement:
count
printcount
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
