python - Convert a list into a sequence of string triples -
i'd convert list like:
["red", "green", "blue"]
into tuple sequence of string triples:
[("red", "red", ""), ("green", "green", ""), ("blue", "blue", "")]
until use method:
def list_to_items(lst): items = [] in lst: items.append((i.upper(), i, "")) return items
but feels bit ugly. there nicer / more pythonic way of doing this?
you can use comprehension:
def list_to_items(lst): return [(item.upper(), item.title(), '') item in lst]
Comments
Post a Comment