Odoo Help

Welcome!

This community 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.

0

What is the difference between [] and {}?

By
henro
on 6/10/15, 4:02 AM 454 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

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

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