Skip to Content
Menu
This question has been flagged
2 Replies
3272 Views

for example :

res = {}
ids = []
So what is the difference in these two?

Thanks in advance

Avatar
Discard
Best Answer

Yes, the previous comment is correct.

res = {} is a dictionary

ids = [] is a list

Dictionaries have keys and values, stored like this:

res = {
     'key1': 'value1',
     'key2': 'value2',
}
print res['key1'] # This will print "value1"
print res['key2'] # This will print "value2"

Lists have only indices and values, stored like this:

ids = ['this', 'that', 'foo', 'bar']
print ids[0] # This will print "this"
print ids[1] # This will print "that"
print ids[2] # This will print "foo"
print ids[3] # This will print "bar"


Avatar
Discard

This is also a Set res = {1,2,3} That is not a dict but is using {...}

Best Answer

this is the data concept of python list and dictionary https://docs.python.org/2/tutorial/datastructures.html

Avatar
Discard