Python Forum
Removing dublicates from a string
Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Removing dublicates from a string
#6
actually, without printing within function it's better - this way it can be used in different ways. And supplying string as argument is great
def remove_duplicates(item):
    ans = "".join(set(item))
    ans_length = len(item) - len(ans)
    return (ans, ans_length)
   
print(remove_duplicates('abccbafg'))

# but also you can do
dedup, length = remove_duplicates('abbafg')
print('There just {} unique element'.format(length))
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Messages In This Thread
Removing dublicates from a string - by JoeNancy - May-18-2018, 12:33 PM
RE: Removing dublicates from a string - by buran - May-18-2018, 12:38 PM
RE: Removing dublicates from a string - by JoeNancy - May-19-2018, 09:18 AM
RE: Removing dublicates from a string - by JoeNancy - May-19-2018, 10:40 AM
RE: Removing dublicates from a string - by buran - May-19-2018, 11:42 AM
RE: Removing dublicates from a string - by JoeNancy - May-20-2018, 12:55 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Help with removing spaces and tabs from a string msqpython 14 4,204 Jan-21-2021, 10:48 PM
Last Post: deanhystad
  Removing string within string fivestar 2 3,157 Oct-20-2017, 04:30 AM
Last Post: Skaperen

Forum Jump:

User Panel Messages

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