Repository: childsish/dynamic-yaml

Issue:
[Enhancement] - Method to resolve the dynamic object
Ran into the issue when trying to pass in a list to a pandas dataframe. I was trying to define some columns, but the list of columns wouldn't resolve. See below example:

```python
import dynamic_yaml
import pandas as pd

yml = '''
names:
  n1: "name1"
  n2: "name2"
columns:
  - "{names.n1}"
  - "{names.n2}"
'''


if __name__ == '__main__':
    config = dynamic_yaml.load(yml)

    df = pd.DataFrame(columns=config.columns)

    print(df.columns)
```
Yeilds:
```
Index(['{names.n1}', '{names.n2}'], dtype='object')
```

So either after a fix that resolves the object when passed, or a method I can call on the object such as `config.columns.as_list()` or `config.columns.as_set()` or `config.columns.resolve()`. Not sure what the best approach is.

Current approach is to unpack and store in a variable. Roughly the following:
```python
cols = [config.columns[x] for x in range(len(config.columns))]
```

Discussion:

Patch:
diff --git a/dynamic_yaml/yaml_wrappers.py b/dynamic_yaml/yaml_wrappers.py
index 14c5ecc..1a08d27 100644
--- a/dynamic_yaml/yaml_wrappers.py
+++ b/dynamic_yaml/yaml_wrappers.py
@@ -78,6 +78,10 @@ class YamlList(DynamicYamlObject, MutableSequence):
         super().__setattr__('_collection', list(*args, **kwargs))
         super().__setattr__('_root', YamlDict([(YamlList.ROOT_NAME, self)]))
 
+    def __iter__(self):
+        for i in range(len(self)):
+            yield self[i]
+
     def insert(self, index: int, object):
         super().__getattribute__('_collection').insert(index, object)
 


Test patch:
diff --git a/tests/test_dynamic_yaml.py b/tests/test_dynamic_yaml.py
index c666952..3cd4bee 100644
--- a/tests/test_dynamic_yaml.py
+++ b/tests/test_dynamic_yaml.py
@@ -197,6 +197,34 @@ class TestDynamicYaml(TestCase):
         res = load(config, recursive=True)
         inner_test(**res)
 
+    def test_list_iteration(self):
+        config = '''
+        targets:
+          v1: value1
+          v2: value2
+        query:
+          - '{targets.v1}'
+          - '{targets.v2}'
+        '''
+
+        res = load(config)
+        self.assertEqual(['value1', 'value2'], list(res.query))
+
+    def test_dict_iteration(self):
+        config = '''
+        targets:
+          v1: value1
+          v2: value2
+        query:
+          v1: '{targets.v1}'
+          v2: '{targets.v2}'
+        '''
+
+        res = load(config)
+        self.assertEqual(['v1', 'v2'], list(res.query))
+        self.assertEqual(['value1', 'value2'], list(res.query.values()))
+        self.assertEqual([('v1', 'value1'), ('v2', 'value2')], list(res.query.items()))
+
 
 if __name__ == '__main__':
     import sys