open(plaintext_b_filename, 'w').write(pb)
```
+```python Collapsed="false"
+pb = """dear uncle wilhelm as you promised we thoroughly enjoyed our visit to your cousin in lincoln and
+found it most informative stop the beautiful cathedral almost justified our visit on its own and our
+hosts shared with us some interesting drawings of the towers you mentioned stop they graciously
+allowed me to copy the sketches and explained much about how the towers are built and why stop as
+usual i will send you my notes and sketches via our dear friend jessica who has promised to ensure
+their safe delivery stop really i must congratulate our hosts in the local scout groups for the
+marvellous way in which they have organised our travel though some of the scouts have been rather
+more solicitous than we had expected asking rather a lot of questions about our plans stop generally
+i hope they were satisfied with the answers that we gave but we feel that we are at risk of
+overstaying our welcome so we will return to london on tuesday stop even though we have enjoyed our
+time together there has been some debate among the group about where we should visit next stop there
+are so many interesting sites to visit along the majestic thames estuary so we have decided to split
+into two groups stop ralf will lead one party on a tour of the kent coast while i am very much
+looking forward to exploring the essex marshes stop do let me know if you have a better idea but i
+have been told that canewdons fifteenth century church affords an elevation with a wide view of
+the surrounding lands in this otherwise rather flat landscape and is the site of another fascinating
+tower which i will be certain to sketch for you stop finally if you have any further requests for
+specific information then perhaps you could leave a message for me at the post office there stop karl
+message ends"""
+```
+
+```python Collapsed="false"
+spb = sanitise(pb)
+```
+
```python Collapsed="false"
pbs = pb.split()
[pbs[i+1] for i, w in enumerate(pbs) if w == 'stop']
```
```python Collapsed="false"
-cat(w[0] for w in pbs)
+pbs = pb.split()
+cat(pbs[i+1][0] for i, w in enumerate(pbs) if w == 'stop')
+```
+
+```python Collapsed="false"
+wcat(segment(cat(w[0] for w in pbs)))
+```
+
+```python Collapsed="false"
+wcat(segment(cat(w[1] for w in pbs if len(w) > 1)))
+```
+
+```python Collapsed="false"
+wcat(segment(cat(w[-1] for w in reversed(pbs))))
+```
+
+```python Collapsed="false"
+max([len(w) for w in pbs])
```
```python Collapsed="false"
```python Collapsed="false"
tt = ''.maketrans('rdf', 'RDF')
pbcap = wcat(pb.split()).translate(tt)
+spbcap = wcat(spb.split()).translate(tt)
pbcap
```
print(pbcap2)
```
+```python Collapsed="false"
+wcat(chunks(spb, 5))
+```
+
+```python Collapsed="false"
+cat(w[-1] for w in chunks(spb, 5))
+```
+
+```python Collapsed="false"
+locR = [i for i, c in enumerate(spb) if c == 'r']
+locD = [i for i, c in enumerate(spb) if c == 'd']
+locF = [i for i, c in enumerate(spb) if c == 'f']
+len(locR), len(locD), len(locF)
+```
+
+```python Collapsed="false"
+triples = []
+for r in locR:
+ for d in locD:
+ for f in locF:
+ if d > r:
+ if d - r == f - d:
+ triples += [(r, d, f, d - r)]
+triples
+```
+
+```python Collapsed="false"
+t = cat(c if c.isupper() else '.' for c in pbscap)
+col = 305 % 32
+tcs = chunks(spb, 32)
+stcs = [wcat([c[:col], c[col], c[col+1:]]) for c in tcs]
+print(lcat(stcs))
+```
+
+```python Collapsed="false"
+results = []
+for l in range(1, 40):
+ for i in range(l):
+ cs = chunks(spb, l, fillvalue=' ')
+ t = cat(c[i] for c in cs)
+ f = Ptrigrams(t)
+ results += [{'l': l, 'i': i, 't': t, 'f': f * l}]
+len(results)
+```
+
+```python Collapsed="false"
+list(sorted(results, key=lambda r: r['f']))[-4:]
+```
+
+```python Collapsed="false"
+rdfresults = [r for r in results if 'rdf' in r['t']]
+len(rdfresults)
+```
+
+```python Collapsed="false"
+rdfresults
+```
+
```python Collapsed="false"
```