import re
import sys


def format_list(lst):
    return u", ".join([u"'%s'" % (elem,) for elem in lst])


def format_string(string, args):
    """Format string like str.format does in Python >= 2.5

    Arguments:
    - string - template string
    - args - arguments dictionary
    """
    for k, v in args.items():
        if sys.version_info.major >= 3:
            v_item = str(v)
        else:
            v_item = unicode(v)
        string = re.sub(u'\\{%s\\}' % k, lambda _: v_item, string)
    return string
