Did I find the right examples for you? yes no      Crawl my project      Python Jobs

# listdiff.listdiff

All Samples(8)  |  Call(4)  |  Derive(0)  |  Import(4)
```Given two lists, returns a "diff" list, with Hole instances inserted
as necessary.
```

```        def listdiff(list1, list2):
"""
Given two lists, returns a "diff" list, with Hole instances inserted
as necessary.
"""
hole = Hole()

# Special case.
if list1 == list2 == []:
return []

best_size, offset1, offset2 = longest_common_substring(list1, list2)

result = []

if best_size == 0:
result.append(hole)
if offset1 > 0 and offset2 > 0:
# There's leftover stuff on the left side of BOTH lists.
result.extend(listdiff(list1[:offset1], list2[:offset2]))
elif offset1 > 0 or offset2 > 0:
# There's leftover stuff on the left side of ONLY ONE of the lists.
result.append(hole)
if best_size > 0:
result.extend(list1[offset1:offset1+best_size])
if (offset1 + best_size < len(list1)) and (offset2 + best_size < len(list2)):
# There's leftover stuff on the right side of BOTH lists.
result.extend(listdiff(list1[offset1+best_size:], list2[offset2+best_size:]))
elif (offset1 + best_size < len(list1)) or (offset2 + best_size < len(list2)):
# There's leftover stuff on the right side of ONLY ONE of the lists.
result.append(hole)
return result
```

```
from brain import Brain # relative import
from listdiff import listdiff # relative import
import re

```
```                brain = Brain(tokens)
else:
brain = Brain(listdiff(brain, tokens))
self.brain = brain

```

```from brain import Brain # relative import
from listdiff import listdiff # relative import
import re

class NoMatch(Exception):
```
```                brain = Brain(tokens)
else:
brain = Brain(listdiff(brain, tokens))
self.brain = brain

```

```
from brain import Brain # relative import
from listdiff import listdiff # relative import
import re

```
```                brain = Brain(tokens)
else:
brain = Brain(listdiff(brain, tokens))
self.brain = brain

```

```
from brain import Brain # relative import
from listdiff import listdiff # relative import
import re

```
```                brain = Brain(tokens)
else:
brain = Brain(listdiff(brain, tokens))
self.brain = brain

```