python - Convert a list into a quadruple tuple sequence -
based on this question, i'm interested in converting list like:
["red", "green", "blue"]
into tuple sequence of string triple , adding counter (integer):
[("red", "red", "", 0), ("green", "green", "", 1), ("blue", "blue", "", 2)]
usually i'd write method like:
def list_to_items(lst): items = [] i,j in enumerate(lst): items.append((j.upper(), j, "", i)) return items
is there nicer / more pythonic way of doing this?
[(y.upper(), y, "", x) x, y in enumerate(["red", "green", "blue"])]
Comments
Post a Comment