exercices de manipulation des structures de données
This commit is contained in:
parent
5728bb1834
commit
26cc76dcc1
@ -37,8 +37,8 @@ def setup(app):
|
||||
app.add_config_value('correction', False, 'env')
|
||||
app.add_config_value('exercice', False, 'env')
|
||||
|
||||
exercice = True
|
||||
correction = True
|
||||
exercice = False
|
||||
correction = False
|
||||
|
||||
# Add any paths that contain templates here, relative to this directory.
|
||||
templates_path = ['_templates']
|
||||
|
@ -343,6 +343,15 @@ Traduction d'une structure de données dans une autre
|
||||
{ 'low': '192.168.0.8', 'high': '192.168.0.35', 'only_unknown': False },
|
||||
],
|
||||
},
|
||||
{
|
||||
'address': '192.168.0.1',
|
||||
'mask': '255.255.255.0',
|
||||
'dynamicRanges': [
|
||||
{ 'low': '192.168.0.5', 'high': '192.168.0.12', 'only_unknown': True },
|
||||
{ 'low': '192.168.0.50', 'high': '192.168.0.55', 'only_unknown': False },
|
||||
],
|
||||
},
|
||||
|
||||
]
|
||||
|
||||
En cette structure de données :
|
||||
@ -361,6 +370,14 @@ Traduction d'une structure de données dans une autre
|
||||
{ low: '192.168.0.8', high: '192.168.0.35', only_unknown: false },
|
||||
],
|
||||
},
|
||||
{
|
||||
'address': '192.168.0.1',
|
||||
'mask': '255.255.255.0',
|
||||
'dynamicRanges': [
|
||||
{ 'low': '192.168.0.5', 'high': '192.168.0.12', 'only_unknown': True },
|
||||
{ 'low': '192.168.0.50', 'high': '192.168.0.55', 'only_unknown': False },
|
||||
],
|
||||
},
|
||||
]
|
||||
|
||||
.. ifconfig:: correction
|
||||
@ -369,7 +386,6 @@ Traduction d'une structure de données dans une autre
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
FIXME
|
||||
>>> from pprint import pprint
|
||||
pprint(l)
|
||||
[{'address': '192.168.0.0',
|
||||
@ -390,17 +406,37 @@ Traduction d'une structure de données dans une autre
|
||||
'mask': '255.255.255.0'}]
|
||||
>>> newdata = []
|
||||
>>> for i in l:
|
||||
... if i['add
|
||||
KeyboardInterrupt
|
||||
>>> addresses = [i['address'] for i in l]
|
||||
>>> addresses
|
||||
['192.168.0.0', '192.168.0.0']
|
||||
>>> for i in l:
|
||||
... if i['address'] in [i['address'] for i in newdata]:
|
||||
... if i['address'] not in [j['address'] for j in newdata]:
|
||||
... newdata.append(i)
|
||||
... else:
|
||||
... for k in newdata:
|
||||
... if k['address'] == i['address']:
|
||||
... k['dynamicRanges'].extend(i['dynamicRanges'])
|
||||
...
|
||||
File "<stdin>", line 2
|
||||
if i['address'] in [i['address'] for i in newdata]:
|
||||
|
||||
>>> pprint(newdata)
|
||||
[{'address': '192.168.0.0',
|
||||
'dynamicRanges': [{'high': '192.168.0.12',
|
||||
'low': '192.168.0.5',
|
||||
'only_unknown': True},
|
||||
{'high': '192.168.0.55',
|
||||
'low': '192.168.0.50',
|
||||
'only_unknown': False},
|
||||
{'high': '192.168.0.45',
|
||||
'low': '192.168.0.12',
|
||||
'only_unknown': True},
|
||||
{'high': '192.168.0.35',
|
||||
'low': '192.168.0.8',
|
||||
'only_unknown': False}],
|
||||
'mask': '255.255.255.0'},
|
||||
{'address': '192.168.0.1',
|
||||
'dynamicRanges': [{'high': '192.168.0.12',
|
||||
'low': '192.168.0.5',
|
||||
'only_unknown': True},
|
||||
{'high': '192.168.0.55',
|
||||
'low': '192.168.0.50',
|
||||
'only_unknown': False}],
|
||||
'mask': '255.255.255.0'}]
|
||||
>>>
|
||||
|
||||
.. ifconfig:: exercice
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user