----- Original Message ----- > I would like to build an array of dictionaries. Most of the > dictionary example on the net are for single dictionary. > > dict = {'a':'a','b':'b','c':'c'} > dict2 = {'a':'a','b':'b','c':'c'} > dict3 = {'a':'a','b':'b','c':'c'} > > arr = (dict,dict2,dict3) > > What is the syntax to access the value of dict3->'a'? > > Thank you. > > -- > https://mail.python.org/mailman/listinfo/python-list >
Hi, arr = (dict,dict2,dict3) builds a tuple. If you want to build a (ordered) List, which is the closest type to array (arrays don't exists in python), you may write myList = [dict, dict2, dict3] you can access 'a' by writing myList[2]['a'] Additionally: myList[0] -> 1st element myList[-1] -> last element myList[3:] -> list of elements of myList from the the 4th element to the last Accessing a list element or a dictionary value is done through the same operator []. That can be confusing at the very beginning, you'll get used to it eventually. JM -- IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you. -- https://mail.python.org/mailman/listinfo/python-list