-1

Let's say we have the following (but actually on a much larger scale):

ABCDEF
GHIJKL
MNOPQR

Is there a way to rotate it to read as the following:

FLR
DKQ
DJP
CIO
BHN
AGM

I wouldn't know where to start on account of it being Monday morning. Thanks,

JJ

pee2pee
  • 3,619
  • 7
  • 52
  • 133
  • 1
    How are you storing your inputs and outputs? Matrices, several arrays? One option you have is creating matrices with the ASCII value of the characters and then use the transpose operator to obtain your desired output. –  Dec 12 '16 at 10:33
  • I'm currently looking at a text file - there's a laborious way I can think of (each line is exactly 75 characters long) but will look at what you suggested – pee2pee Dec 12 '16 at 10:34
  • Briefly: click the linked question, and scroll to the Python answer. – TigerhawkT3 Dec 12 '16 at 10:42

1 Answers1

1

This is basically just transforming the columns into the rows. This can be achieved with zip():

lines = []
with open('file.txt') as f:
    for line in f:
        lines.append(line.rstrip())

cols = zip(*lines)
for col in list(cols)[::-1]:
    print(''.join(col))

Outputs:

FLR
EKQ
DJP
CIO
BHN
AGM
Chris_Rands
  • 38,994
  • 14
  • 83
  • 119