structure in Python
Christopher Koppler
klapotec at chello.at
Mon Oct 20 21:21:39 EDT 2003
On Mon, 20 Oct 2003 18:13:48 -0500, "Alberto Vera" <avera at coes.org.pe>
wrote:
>Hello:
>I have the next structure:
>[key1,value1,value2]
>
>['A',1,5]
>['B',6,7]
>
>How Can I make it using Python?
Use a dictionary with the values in lists:
>>>listdict = {'A': [1, 5], 'B': [6, 7]}
>>> print listdict
{'A': [1, 5], 'B': [6, 7]}
>
>How Can I update the value of 6?
>>> print listdict['B'][0]
6
>>> listdict['B'][0] = 28
>>> print listdict['B'][0]
28
>How Can I insert a key called "C" and its values?
>>> listdict['C'] = [1, 2, 3]
>>> print listdict
{'A': [1, 5], 'C': [1, 2, 3], 'B': [28, 7]}
>How Can I delete a key called "B"?
>>> del listdict['B']
>>> print listdict
{'A': [1, 5], 'C': [1, 2, 3]}
>How Can I search a key called "A"(parameter) and get its values?
>>> if 'A' in listdict:
... print listdict['A']
...
[1, 5]
>
>Regards
Try searching the Python documentation or take the Tutorial:
http://www.python.org/doc/current/tut/tut.html
--
Christopher
More information about the Python-list
mailing list