Python: textwrap.wrap(), OrderedDict.fromkeys()

Demonstrating wrap and OrderedDict

nick3499
1 min readSep 22, 2017

First, enter a text string, e.g. AABCAAADA. Followed by a divisor integer, e.g. 3.

AABCAAADA
3

The program returns:

AB
CA
AD

Notice how redundant letters are left out.

textwrap.wrap(S, N) is used to separate AABCAAADA into three equal parts: ['AAB', 'CAA', 'ADA'].

for i in t:
u = ''.join(i)

u stores the following:

AAB
CAA
ADA

''.join(OrderedDict.fromkeys(u)) is used to print the following. Notice how duplicate letters are left out.

AB
CA
AD

--

--

nick3499
nick3499

Written by nick3499

coder of JavaScript and Python

No responses yet