+ 2

What is the point of lists, tuples, sets, and dictionaries?

They are all so similar! Why not just use lists and remember what and what not to do to that list to keep the code working? Why must we have 4 collection types in python? It doesn't make sense to me - why make 4 when just 1 works?

1st Dec 2024, 9:21 PM
The Big Cheese 1211-1967
The Big Cheese 1211-1967 - avatar
2 ответов
+ 8
The Big Cheese 1211-1967 , it is up to you what you are going to use, you are not forced to do anything: you make your own luck. you may try to use lists for all purposes of use, but they are not really dedicated for all use cases. for example: > set have several methods that can make operations like `intersection, ... `. trying this with a large number of members from a list, does not have a good performance. > set does not allow duplicates as data. so if you are going to remove all duplicated data is very simple with sets, by having very hight speed of execution. > searching in tuples is faster than searching in lists. > dictionary does have a high speed when doing lookups or counting compared to the performance of lists. > ... to get a more clear picture with the pro and cons of python collections, use the text you posted and ask chatGPT 4.o.
1st Dec 2024, 9:40 PM
Lothar
Lothar - avatar
+ 1
Lothar (How do you make those links?), That makes much more sense: 1. I can see why you wouldn't want duplicate data though. Doing it manually with loops and all is very slow and is a waste of space so I suppose sets would be very useful. 2. If tuples really are easier to search through lists then it might be very useful to use them in a large database. 3. Dictionaries could be used for, well, dictionaries! Also, they could be used for assigning specific data to a certain other piece of data so it would be very useful for creating AI neural networks.
1st Dec 2024, 11:59 PM
The Big Cheese 1211-1967
The Big Cheese 1211-1967 - avatar