Teil VIII: Die Hülle

Kapitel 27: Typische Aufgaben in Python

  1. Reguläre Ausdrücke vermeiden. Dieses Programm ist lang und mühsam, aber nicht besonders kompliziert. Versuchen Sie zu verstehen, wie es funktioniert. Ob das für Sie einfacher ist als reguläre Ausdrücke, hängt von vielen Faktoren ab, z.B. davon, wie sehr Sie mit regulären Ausdrücken vertraut sind und ob Sie die Funktionen im string-Modul gern benutzen. Sie sollten benutzen, was für Sie am besten funktioniert.

    file = open('pepper.txt') text = file.read( ) paragraphs = text.split('\n\n') def find_indices_for(big, small): indices = [ ] cum = 0 while 1: index = big.find(small) if index == −1: return indices indices.append(index+cum) big = big[index+len(small):] cum = cum + index + len(small) ...

Get Einfüehrung in Python now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.