YAML key consisting of a list of elements
<p>I need to have a list of elements as a key, so that I can check if several conditions are met. 
Example (don't know if this is possible and if the syntax is correct):</p>

<pre><code>mapping:
  c_id:
    [pak, gb]: '4711'
    [pak, ch]: '4712'
    [pak]: '4713'
  d_id:
    .
    .
    .
</code></pre>

<p>Now I need to know if it is possible to have an approach as in the example.</p>

<p>The syntax for your YAML is correct. The only trick is that because in Python a key has to be immutable you need to specify access to the complex key as a tuple:</p>

<pre><code>import ruamel.yaml

yaml_str = """\
mapping:
  c_id:
    [pak, gb]: '4711'
    [pak, ch]: '4712'
    [pak]: '4713'
"""

data = ruamel.yaml.round_trip_load(yaml_str)
print(data['mapping']['c_id'][('pak', 'gb')])
</code></pre>

<p>gives:</p>

<pre><code>4711
</code></pre>

<p>Please note that this is not possible with PyYAML, as it doesn't support sequences as keys, you have to use <a href="https://pypi.python.org/pypi/ruamel.yaml/" rel="nofollow"><code>ruamel.yaml</code></a> (disclaimer: I am the author of that package)</p>

python yaml pyyaml