+ 2

What is the major difference btw list and dictionary in python?

Please give an eleborated answer. P.s. I am totally new to python, thanks in advance

4th Apr 2018, 2:17 PM
Kapil
Kapil - avatar
2 ответов
4th Apr 2018, 2:39 PM
Memphis Reigns
Memphis Reigns - avatar
+ 2
List is a set of values accessible by index (ordinal number): mylist = [1,2,'solo','learn', 4.57] index starts with zero, so the first element of the list has index 0 and the last - list's lenght - 1: >>> print(mylist[0]) 1 Dicrtionary is a kind of set of pairs of key-value. Just think of it as of a common dictionary wich has word and it's definition. It means, that you can access each value by its key, not index. >>> mydict = {1:'a', 'akey':'avalue', 'onemore':4.75} >>> print(mydict['akey']) avalue You can add a value to a list just by appending it, but you need to add both key and value to add a value to a dictionary. Both list and dictionary values could be lists themselves.
4th Apr 2018, 2:43 PM
strawdog
strawdog - avatar