+ 1

Python : Lists, Dicts, Tuples

Can anyone care to explain what these have in difference and when to use them?

1st Apr 2019, 3:49 AM
thariq
thariq - avatar
2 Antworten
+ 1
This is covered in the Python 3 training under More Type. But, from what I understand: -Lists use square brackets [] -Tuples use parentheses () -Dict use curly bracket {} -Tuples: use to create a fixed list to reference and will not need updating. (calendar months, days of the week, names of your children after a vasectomy) -Lists: use to create a list you may need to update. (top 10 books, countries visited, namea of your children before a vasectomy) -Dicts: used to create a collection of unordered data that can be referenced by a key, as opposed to the indexed position used for a list. (names/ numbers in your phone, product name/ product price for inventory, name/ room number for hotels) -Lists, creats a list of items that is indexed. Items can replaced. The list can be added to or have items deleted from. -Tuples, are similar to lists but items cannot be edited. NO adding to, deleting or changing. (immutable) *** This is why Tuples require least amount of memory to use *** -Dicts are data structure that has a hash table of key:value pairs. Dict is an unordered collection. -From a fellow Python Noob
1st Apr 2019, 5:14 AM
Jon Jesh
Jon Jesh - avatar