Python Forum
Delete minimum occurence in a string
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Delete minimum occurence in a string
#1
Hi,
I have to delete minimum number of character in a string.
I saw that there is Counter but I don't know how to use it.
This is my code for now:
word  = "abecedario alpaca"
char = ''
word_list = []
#add a string into a list 
for c in word:
  word_list.append(c)
#print(word_list)
#a counter that check if inside a list there is a char 
count = 0
for counter in word_list: #for any elements of list --> is there char? 
  if counter == char:
    count = count + 1 #counter 

print(count)
This is text :
Quote:Given a string s consisting of n lowercase letters, you have to delete the minimum number of characters from s so that every letter in s appears a unique number of times. We only care about the occurrences of letters that appear at least once in result.
Regards,
RavCoder
Reply


Messages In This Thread
Delete minimum occurence in a string - by RavCOder - Nov-11-2019, 02:13 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
Question [SOLVED] Delete specific characters from string lines EnfantNicolas 4 2,228 Oct-21-2021, 11:28 AM
Last Post: EnfantNicolas
Thumbs Up [SOLVED] Find last occurence of pattern in text file? Winfried 4 4,411 Aug-13-2021, 08:21 PM
Last Post: Winfried
  How to get indices of minimum time difference Mekala 1 2,171 Nov-10-2020, 11:09 PM
Last Post: deanhystad
  How to get index of minimum element between 3 & 8 in list Mekala 2 2,537 Nov-10-2020, 12:56 PM
Last Post: DeaD_EyE
  Delete lines from a string that contains a keyword JellyCreeper6 4 3,553 Oct-30-2020, 10:46 AM
Last Post: JellyCreeper6
  Finding MINIMUM number in a random list is not working Mona 5 3,053 Nov-18-2019, 07:27 PM
Last Post: ThomasL
  Occurence Adem 3 2,706 Nov-08-2019, 03:17 PM
Last Post: Adem
  Minimum size Amniote 8 3,840 Jul-10-2019, 02:58 PM
Last Post: nilamo
  Armstrong in minimum lines Gaurav 1 2,008 Sep-03-2018, 03:46 PM
Last Post: j.crater
  Watson Personality Insight: minimum number of words kiton 0 2,741 Apr-28-2018, 03:28 PM
Last Post: kiton

Forum Jump:

User Panel Messages

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