OLD | NEW |
1 # Copyright (c) 2012 Google Inc. All rights reserved. | 1 # Copyright (c) 2012 Google Inc. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 from __future__ import with_statement | 5 from __future__ import with_statement |
6 | 6 |
7 import errno | 7 import errno |
8 import filecmp | 8 import filecmp |
9 import os.path | 9 import os.path |
10 import re | 10 import re |
(...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
385 | 385 |
386 | 386 |
387 # From Alex Martelli, | 387 # From Alex Martelli, |
388 # http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52560 | 388 # http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52560 |
389 # ASPN: Python Cookbook: Remove duplicates from a sequence | 389 # ASPN: Python Cookbook: Remove duplicates from a sequence |
390 # First comment, dated 2001/10/13. | 390 # First comment, dated 2001/10/13. |
391 # (Also in the printed Python Cookbook.) | 391 # (Also in the printed Python Cookbook.) |
392 | 392 |
393 def uniquer(seq, idfun=None): | 393 def uniquer(seq, idfun=None): |
394 if idfun is None: | 394 if idfun is None: |
395 def idfun(x): return x | 395 idfun = lambda x: x |
396 seen = {} | 396 seen = {} |
397 result = [] | 397 result = [] |
398 for item in seq: | 398 for item in seq: |
399 marker = idfun(item) | 399 marker = idfun(item) |
400 if marker in seen: continue | 400 if marker in seen: continue |
401 seen[marker] = 1 | 401 seen[marker] = 1 |
402 result.append(item) | 402 result.append(item) |
403 return result | 403 return result |
404 | 404 |
405 | 405 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
443 return | 443 return |
444 visited.add(node) | 444 visited.add(node) |
445 visiting.add(node) | 445 visiting.add(node) |
446 for neighbor in get_edges(node): | 446 for neighbor in get_edges(node): |
447 Visit(neighbor) | 447 Visit(neighbor) |
448 visiting.remove(node) | 448 visiting.remove(node) |
449 ordered_nodes.insert(0, node) | 449 ordered_nodes.insert(0, node) |
450 for node in sorted(graph): | 450 for node in sorted(graph): |
451 Visit(node) | 451 Visit(node) |
452 return ordered_nodes | 452 return ordered_nodes |
OLD | NEW |