+ 15

What is the meaning of tuples are faster than lists?

10th Dec 2018, 2:07 PM
Chandini
Chandini - avatar
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 😊
10th Dec 2018, 3:00 PM
Kishalaya Saha
Kishalaya Saha - avatar
+ 17
Thank you sir
6th Jan 2019, 1:00 PM
Chandini
Chandini - avatar
+ 11
Nice explanation Kishalaya Saha Clears a lot doubt
6th Jan 2019, 10:12 AM
Charan Leo25
Charan Leo25 - avatar
+ 5
Charan LEo25 thanks, glad I could help 😊 👍
6th Jan 2019, 12:26 PM
Kishalaya Saha
Kishalaya Saha - avatar
+ 5
You're welcome, Chandini 😊
6th Jan 2019, 1:11 PM
Kishalaya Saha
Kishalaya Saha - avatar