I've a file with alternating lines, chords followed by lyrics:
C G Am
See the stone set in your eyes,
F C
see the thorn twist in your side,
G Am F
I wait for you
How could I merge subsequent lines in order to produce an output like the following, while keeping track of the character position:
(C)See the (G)stone set in your (Am)eyes,
see the t(F)horn twist in your s(C)ide,
I (G)wait for y(Am)ou(F)
From How do I read two lines from a file at a time using python it can be seen that iterating over the file 2 lines at a time can be done with
with open('lyrics.txt') as f:
for line1, line2 in zip(f, f):
... # process lines
but how can the lines be merged so that line 2 is split according to character positions (of chords) from line 1? A simple
chords = line1.split()
has no position information and
for i, c in enumerate(line1):
...
gives separate characters, not the chords.