/usr/share/doc/pyxplot/html/sect0048.html is in pyxplot-doc 0.9.2-4.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta name="generator" content="plasTeX" />
<meta content="text/html; charset=utf-8" http-equiv="content-type" />
<title>PyXPlot Users' Guide: Dictionaries</title>
<link href="sec-vectors.html" title="Vectors and matrices" rel="next" />
<link href="sect0047.html" title="Vectors versus lists" rel="prev" />
<link href="chap-progDataTypes.html" title="Programming: Pyxplot’s data types" rel="up" />
<link rel="stylesheet" href="styles/styles.css" />
</head>
<body>
<div class="navigation">
<table cellspacing="2" cellpadding="0" width="100%">
<tr>
<td><a href="sect0047.html" title="Vectors versus lists"><img alt="Previous: Vectors versus lists" border="0" src="icons/previous.gif" width="32" height="32" /></a></td>
<td><a href="chap-progDataTypes.html" title="Programming: Pyxplot’s data types"><img alt="Up: Programming: Pyxplot’s data types" border="0" src="icons/up.gif" width="32" height="32" /></a></td>
<td><a href="sec-vectors.html" title="Vectors and matrices"><img alt="Next: Vectors and matrices" border="0" src="icons/next.gif" width="32" height="32" /></a></td>
<td class="navtitle" align="center">PyXPlot Users' Guide</td>
<td><a href="index.html" title="Table of Contents"><img border="0" alt="" src="icons/contents.gif" width="32" height="32" /></a></td>
<td><a href="sect0288.html" title="Index"><img border="0" alt="" src="icons/index.gif" width="32" height="32" /></a></td>
<td><img border="0" alt="" src="icons/blank.gif" width="32" height="32" /></td>
</tr>
</table>
</div>
<div class="breadcrumbs">
<span>
<span>
<a href="index.html">PyXPlot Users' Guide</a> <b>:</b>
</span>
</span><span>
<span>
<a href="sect0001.html">Introduction to PyXPlot</a> <b>:</b>
</span>
</span><span>
<span>
<a href="chap-progDataTypes.html">Programming: Pyxplot’s data types</a> <b>:</b>
</span>
</span><span>
<span>
<b class="current">Dictionaries</b>
</span>
</span>
<hr />
</div>
<div><h1 id="a0000000049">6.4 Dictionaries</h1>
<p>Dictionaries, also known as associative arrays or content-addressable memories in other programming languages, store collections of objects, each of which has a unique name (or key). Objects are addressed by name, rather than by number: </p><p> <tt class="ttfamily">pyxplot> <b class="bfseries">myDict = {’red’:colors.red, ’green’:colors.green}</b></tt><br /><tt class="ttfamily">pyxplot> <b class="bfseries">myDict[’blue’] = colors.blue</b></tt><br /><tt class="ttfamily">pyxplot> <b class="bfseries">print myDict[’green’]</b></tt><br /><tt class="ttfamily">cmyk(1,0,1,0)</tt><br /><tt class="ttfamily">pyxplot> <b class="bfseries">call myDict.delete(’green’)</b></tt><br /><tt class="ttfamily">pyxplot> <b class="bfseries">call myDict.delete(’blue’)</b></tt><br /><tt class="ttfamily">pyxplot> <b class="bfseries">myDict[’purple’] = colors.purple</b></tt><br /><tt class="ttfamily">pyxplot> <b class="bfseries">print myDict</b></tt><br /><tt class="ttfamily">{"purple":cmyk(0.45,0.86,0,0), "red":cmyk(0,1,1,0)}</tt> </p><p>As the first line of this example shows, dictionaries can be created by enclosing a list of key–value pairs in curly brackets. As in python, a colon separates each key from its corresponding value, while the list of key–value pairs are comma-separated. That is, the general syntax is: </p><pre>
{ key1:value1 , key2:value2 , ... }
</pre><p>It is also possible to generate an empty dictionary, as <tt class="tt">{}</tt>. Items can later be referenced or assigned by name, where the name is placed in square brackets after the name of the dictionary. Items can be deleted with the dictionary’s <tt class="tt">delete(key)</tt> method. </p><p>It is not an error to assign an item to a name which is already defined in the dictionary; the new assignment overwrites the old object with that name. It is, however, an error to attempt to access a key which is not defined in the dictionary. The method <tt class="tt">hasKey(key)</tt> may be used to test whether a key is defined before attempting to access it. </p><p>Unlike in python, keys <b class="bf">must</b> be strings. </p></div>
<div class="navigation">
<table cellspacing="2" cellpadding="0" width="100%">
<tr>
<td><a href="sect0047.html" title="Vectors versus lists"><img alt="Previous: Vectors versus lists" border="0" src="icons/previous.gif" width="32" height="32" /></a></td>
<td><a href="chap-progDataTypes.html" title="Programming: Pyxplot’s data types"><img alt="Up: Programming: Pyxplot’s data types" border="0" src="icons/up.gif" width="32" height="32" /></a></td>
<td><a href="sec-vectors.html" title="Vectors and matrices"><img alt="Next: Vectors and matrices" border="0" src="icons/next.gif" width="32" height="32" /></a></td>
<td class="navtitle" align="center">PyXPlot Users' Guide</td>
<td><a href="index.html" title="Table of Contents"><img border="0" alt="" src="icons/contents.gif" width="32" height="32" /></a></td>
<td><a href="sect0288.html" title="Index"><img border="0" alt="" src="icons/index.gif" width="32" height="32" /></a></td>
<td><img border="0" alt="" src="icons/blank.gif" width="32" height="32" /></td>
</tr>
</table>
</div>
<script language="javascript" src="icons/imgadjust.js" type="text/javascript"></script>
</body>
</html>
|