+ 15
What is the meaning of tuples are faster than lists?
5 Respostas
+ 13
Tuples, being simple, immutable objects, take less time to create than lists. But the difference in speed is hardly noticeable. Especially for other operations like iterating over elements of a tuple or checking if something is in a tuple, the speeds are comparable to list.
I'd suggest not to worry too much about their relative speeds. When you think the elements in your container would not change, or need to do tuple unpacking, use tuples. Otherwise use lists.
However, I'm not saying that you shouldn't think about using appropriate data structures for making your code efficient. For example, sets, owing to their implementation, have markedly faster lookup time than lists. Numpy arrays are also a lot faster than lists in certain situations.
Hope that helps 😊
+ 17
Thank you sir
+ 11
Nice explanation Kishalaya Saha
Clears a lot doubt
+ 5
Charan LEo25 thanks, glad I could help 😊 👍
+ 5
You're welcome, Chandini 😊