P
P
Python74929462021-01-02 19:07:33
Python
Python7492946, 2021-01-02 19:07:33

How to find repetition in a list in Python?

There is a list

list = ['R ', 'L ', 'U ', 'D ', 'F ', 'B ', "R' ", "L' ", "U' ", "D' ", "F' ", "B' ", 'R2 ', 'L2 ', 'U2 ', 'D2 ', 'F2 ', 'B2 ', "R'2 ", "L'2 ", "U'2 ", "D'2 ", "F'2 ", "B'2 "]


You need to make sure that after randomization there were no repetitions in the resulting list
Example:
F'2 F2 F R' D'2 R'2 F'2 F2 L'2 L'2 F2 F' R R' D2 F'2 F'2 R

For example F '2 and F2 are considered the same

Please help

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Gornostaev, 2021-01-02
@Python7492946

a = ['R ', 'L ', 'U ', 'D ', 'F ', 'B ', "R' ", "L' ", "U' ", "D' ", "F' ", "B' ", 'R2 ', 'L2 ', 'U2 ', 'D2 ', 'F2 ', 'B2 ', "R'2 ", "L'2 ", "U'2 ", "D'2 ", "F'2 ", "B'2 "]
b = {i.replace("'", "") for i in a}

PS Using "list" as a variable name is a bad idea.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question