Skip to content

Instantly share code, notes, and snippets.

@sorXCode
Last active October 15, 2017 16:52
Show Gist options
  • Select an option

  • Save sorXCode/93d34e5d63b023d17aa5fa4534a9fb4a to your computer and use it in GitHub Desktop.

Select an option

Save sorXCode/93d34e5d63b023d17aa5fa4534a9fb4a to your computer and use it in GitHub Desktop.
sol >> Write a function that will return the count of distinct case-insensitive alphabetic characters and numeric digits that occur more than once in the input string. The input string can be assumed to contain only alphabets (both uppercase and lowercase) and numeric digits.
#stepwise solution
def counter(word):
numberList = [] # empty list for numbers
alphaList = [] # empty list for alphabets
#sorting num and alpha from word into resp. list
for ch in word:
if ch.isdigit():
numberList.append(ch)
elif ch.isalpha():
alphaList.append(ch.lower()) #converting to lower case since matching is case-INsensitive
#counting and print only num/alpha occurring more than once
for x in numberList:
count = numberList.count(x)
if count >1:
print "{} --> {} ".format(x,count)
while numberList.count(x) > 1 : #weeding tested num
numberList.remove(x)
for i in alphaList:
count = alphaList.count(i)
if count > 1:
print" {} --> {}".format(i, count)
while alphaList.count(i) > 1: #weeding tested alpha
alphaList.remove(i)
----------------_-------------_-------------_----
#"point-and-kill" solution
def counter(word):
word = list(word.lower())
for i in word:
if (i.isalpha()) or (i.isdigit()):
count = word.count(i)
if (count > 1):
print "{} ={}" %(i,count)
while(word.count(i) > 1):
word.remove(i)
that's all....
code attached...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment