Odoo Help

0

What is the difference between [] and {}?

By
henro
on 6/10/15, 4:02 AM 670 views

for example :

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

Thanks in advance

4
Andre de Kock
On 6/10/15, 11:48 AM

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"


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

Axel Mendoza
on 7/27/15, 4:41 AM
0
Turkesh Patel
On 6/10/15, 4:29 AM

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

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

Register

Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)

Stats

Asked: 6/10/15, 4:02 AM
Seen: 670 times
Last updated: 6/10/15, 5:32 PM