recursive call only for the key values present in internal_dep or skip the ones present in skip list
<p>I have the following code which recursively calls each value in internal_dep,is there a way the function call can be changed to call only for the keys present in internal_dep or skip the call for the ones in skip list?</p>

<pre><code>internal_dep = {'313115': ['313113'], '313117': ['313115'], '313137': ['313136'], '313136': ['313119'], '313119': ['313118'], '313118': ['313117']}
mainlist = ['313137', '317152' , '314449']
skip = ['313113']

def _getdep(item):
    local_list, temp_list = [], []
    temp_list.extend(internal_dep[item])
    local_list.extend(temp_list)
    for new_item in temp_list:
        local_list.extend(_getdep(new_item))
    return local_list

build_dep_list = []
for item in mainlist:
    build_dep_list.append(item)
    build_dep_list.extend(_getdep(item))

print build_dep_list
</code></pre>

<p>ERROR:-</p>

<pre><code>Traceback (most recent call last):
  File "test.py", line 16, in &lt;module&gt;
    build_dep_list.extend(_getdep(item))
  File "test.py", line 10, in _getdep
    local_list.extend(_getdep(new_item))
  File "test.py", line 10, in _getdep
    local_list.extend(_getdep(new_item))
  File "test.py", line 10, in _getdep
    local_list.extend(_getdep(new_item))
  File "test.py", line 10, in _getdep
    local_list.extend(_getdep(new_item))
  File "test.py", line 10, in _getdep
    local_list.extend(_getdep(new_item))
  File "test.py", line 10, in _getdep
    local_list.extend(_getdep(new_item))
  File "test.py", line 6, in _getdep
    temp_list.extend(internal_dep[item])
KeyError: '313113'

EXPECTED OUTPUT:-
['313115', '313113', '313117','313137','313136','313119','313118','313117']
</code></pre>
