#!/usr/bin/env python3 import argparse import string import sys CHARS = ("🇦", "🇧", "🇨", "🇩", "🇪", "🇫", "🇬", "🇭", "🇮", "🇯", "🇰", "🇱", "🇲", "🇳", "🇴", "🇵", "🇶", "🇷", "🇸", "🇹", "🇺", "🇻", "🇼", "🇽", "🇾", "🇿") OFFSET = ord('A') def flag(code): """ Return the Unicode flag emoji for a two-letter country code. """ if len(code) != 2: raise ValueError('country code must be two letters long') if not all(c in string.ascii_letters for c in code): raise ValueError('country code must only contain letters A-Z') return ''.join(CHARS[ord(c) - OFFSET] for c in code.upper()) def main(): parser = argparse.ArgumentParser() parser.add_argument('country_code', nargs='*', help='a two-letter country code (ISO 3166-1)') parser.add_argument('-s', '--sep', help='separator') args = parser.parse_args() if args.country_code: flags = (flag(code) for code in args.country_code) else: parser.print_help() return 1 sep = ' ' if args.sep is None else args.sep print(sep.join(flags)) if __name__ == '__main__': sys.exit(main())