Python Forum
Selecting the first occurrence of a duplicate
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Selecting the first occurrence of a duplicate
#8
(May-24-2021, 11:05 AM)knight2000 Wrote: I'm not sure if that's the correct or best way to go about it, but the results are:
Probably could fix it earlier when parse out the values to not get duplicates,like using CSS selector in BS select() and select_one() to get right tags.
range(len(sequence)) is looked as a bad way in most cases,
can maybe be justified here as use step parameter in range() here,that enumerate() dos not have.

An other way remove duplicate then loop.
prices = [
    "$139,501",
    "$139,501",
    "$137,349",
    "$137,349",
    "$132,955",
    "$132,955",
    "$129,000",
    "$129,000",
]

for item in dict.fromkeys(prices):
    print(item)
Output:
$139,501 $137,349 $132,955 $129,000
Just remove duplicates without care about order would be to use set().
>>> set(prices)
{'$132,955', '$139,501', '$129,000', '$137,349'}
Reply


Messages In This Thread
RE: Selecting the first occurrence of a duplicate - by snippsat - May-24-2021, 11:50 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to get unique entries in a list and the count of occurrence james2009 5 4,393 May-08-2022, 04:34 AM
Last Post: ndc85430
  Selecting text as an input lazerwolf101 2 3,074 May-29-2020, 06:52 AM
Last Post: lazerwolf101
  Checking for one or more occurrence in a list menator01 3 3,552 May-18-2020, 06:44 AM
Last Post: DPaul
  count occurrence of numbers in a sequence and return corresponding value python_newbie09 6 5,677 May-20-2019, 06:33 PM
Last Post: python_newbie09
  selecting a module at run time Skaperen 1 2,932 Jun-23-2018, 01:37 PM
Last Post: gontajones
  Word co-occurrence matrix for a string (NLP) JoeB 2 12,603 Feb-27-2018, 11:21 PM
Last Post: Larz60+
  Maximum Occurrence Letter GalaxyCR 2 4,823 Nov-27-2017, 09:00 PM
Last Post: nilamo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020