Skip to content

Instantly share code, notes, and snippets.

@6r1d
Created January 9, 2013 22:23
Show Gist options
  • Save 6r1d/4497552 to your computer and use it in GitHub Desktop.
Save 6r1d/4497552 to your computer and use it in GitHub Desktop.
SnakeText: new version of an old joke
#!/usr/bin/python
# -*- coding: utf-8 -*-
import codecs
# Open file and load lines
with codecs.open('msg.txt', encoding='utf8') as f:
lines = [line.strip() for line in f]
# Counting lines
linesCount = len(lines)
# Max line length
maxlen = max([len(line) for line in lines])
# Make symbol lists, similar by length from lines
lines = [list(line + ' ' * (maxlen - len(line))) for line in lines]
# Rotate odd lines
lines = [(lines[line_num][::-1] if line_num % 2
!= 0 else lines[line_num]) for line_num in range(len(lines))]
# Show the stuff
print u'\n'.join([''.join([lines[i][j] for i in range(linesCount)])
for j in range(maxlen)])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment