Задать вопрос
@WASDABOO

Как удалить дубликаты из списка?

{'threads/4862302', 'threads/4855381/', 'threads/4867041/', 'threads/4865447', 'threads/4866970/', 'threads/4862317', 'threads/4866935/', 'threads/4867075/', 'threads/4867089', 'threads/4867110/', 'threads/4867132/', 'threads/4867113', 'threads/4867112/', 'threads/4867110', 'threads/4862569', 'threads/4867041', 'threads/4867138', 'threads/4862569/', 'threads/4867083', 'threads/4867144', 'threads/4867092/', 'threads/4867065/', 'threads/4867021', 'threads/4867089/', 'threads/4855381', 'threads/4867061/', 'threads/4867092', 'threads/4866935', 'threads/4867113/', 'threads/4867138/', 'threads/4866941/', 'threads/4866941', 'threads/4867075', 'threads/4867061', 'threads/4866970', 'threads/4860112', 'threads/4867111/', 'threads/4867140/', 'threads/4867132', 'threads/4862850', 'threads/4861918/', 'threads/4867111', 'threads/4867065', 'threads/4867122/', 'threads/4867122', 'threads/4867083/', 'threads/4860986', 'threads/4867145', 'threads/4860986/', 'threads/4867144/', 'threads/4865534', 'threads/4867021/', 'threads/43694', 'threads/4862317/', 'threads/4867145/', 'threads/4864682/', 'threads/4866913/', 'threads/4867140', 'threads/4860112/', 'threads/4865534/', 'threads/4862302/', 'threads/4856417/', 'threads/4856417', 'threads/4864682', 'threads/4867077', '/threads/4883/', 'threads/4866913', 'threads/4865447/', 'threads/4867112', 'threads/4862850/', 'threads/4867077/', 'threads/4861918'}

Из этого списка нужно удалить дубликаты. Но есть один нюанс, во всех дубликатах присутсвует символ "/" в конце.
Как удалить такие дубликаты?
  • Вопрос задан
  • 110 просмотров
Подписаться 1 Простой Комментировать
Решение пользователя Владимир Куц К ответам на вопрос (3)
fox_12
@fox_12 Куратор тега Python
Расставляю биты, управляю заряженными частицами
Ну так нормализуйте - удалите лишнюю '/' там где не надо - да оберните в set как уже посоветовали:

set(x[:-1] if x[-1] == '/' else x for x in data)
где data - ваш список
Ответ написан