+ 1

What are the advantages / disadvantages of using lists or tuples? And dictionaries?

Python

1st Feb 2017, 6:44 AM
Frank Nolasco
Frank Nolasco - avatar
3 Antworten
+ 8
Tuples are set in their ordering and values. Lists are numerically keyed and can be sorted and have values removed or added. Dictionaries can have whatever key you would like and similarly to lists can be adjusted in values and size.
1st Feb 2017, 11:48 PM
Kevin Gilkey-Graham
Kevin Gilkey-Graham - avatar
+ 4
A major difference between Lists and the rest that you 're asking is that Lists are mutable. Tuples and Dictionaries are immutable so their values are fixed. There can be no precise explanation to your question since the real question is what do you want your program to do? If you want to collect values and store them somewhere then Lists is the solution you are searching for, since they can be mutated. If you want to get values from something like a database then Tuples or Dictionaries might be a good solution. Dictionaries give you the perk of a key usage also. So it all depends on what you want to achieve. I'm not sure if this helps.
8th Feb 2017, 2:03 PM
Panagiotis Georgiou
Panagiotis Georgiou - avatar
+ 2
Tuples are fastest data types​ in Python
27th Feb 2017, 4:22 AM
Dmitry Bulgakov
Dmitry Bulgakov - avatar