def colors_to_needle_positions(rows):
needles = []<EOL>for row in rows:<EOL><INDENT>colors = set(row)<EOL>if len(colors) == <NUM_LIT:1>:<EOL><INDENT>needles.append([NeedlePositions(row, tuple(colors), False)])<EOL><DEDENT>elif len(colors) == <NUM_LIT:2>:<EOL><INDENT>color1, color2 = colors<EOL>if color1 != row[<NUM_LIT:0>]:<EOL><INDENT>color1, color2 = color2, color1<EOL><DEDENT>needles_ = _row_color(row, color1)<EOL>needles.append([NeedlePositions(needles_, (color1, color2), True)])<EOL><DEDENT>else:<EOL><INDENT>colors = []<EOL>for color in row:<EOL><INDENT>if color not in colors:<EOL><INDENT>colors.append(color)<EOL><DEDENT><DEDENT>needles_ = []<EOL>for color in colors:<EOL><INDENT>needles_.append(NeedlePositions(_row_color(row, color),<EOL>(color,), False))<EOL><DEDENT>needles.append(needles_)<EOL><DEDENT><DEDENT>return needles<EOL>
Convert rows to needle positions.

    :return:
    :rtype: list