DEV Community

Cover image for Twelve Days of Christmas
Hai Vu
Hai Vu

Posted on

Twelve Days of Christmas

Here is a fun bit: I wrote a little Python script to displays the lyric of Twelve Days of Christmas in 12 lines.

#!/usr/bin/env python3
gifts = [
    'a partridge in a pear tree', 'two turtle doves and', 'three French hens',
    'four calling birds', 'five gold rings', 'six geese a-laying',
    'seven swans a-swimming', 'eight maids a-milking', 'nine ladies dancing',
    'ten lords a-leaping', 'eleven pipers piping', 'twelve drummers drumming'
    ]
days = """first second third fourth fifth sixth seventh eighth
    ninth tenth eleventh twelfth""".split()
for limit, day in enumerate(days, 1):
    gift = '\n  '.join(reversed(gifts[:limit]))
    print(f'On the {day} day of Christmas, my true love gave to me\n  {gift}\n')
Enter fullscreen mode Exit fullscreen mode

Top comments (0)