Stats: 3,182,038 members, 7,915,997 topics. Date: Friday, 09 August 2024 at 01:39 PM |
Nairaland Forum / Young02's Profile / Young02's Posts
(1) (of 1 pages)
![]() |
efosky1246: quite inefficient... see as u talk am self... No be for FUN? tsk... If point-and-kill is what u prefer, have it! 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...
|
![]() |
solution in Python(2) <code> 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)and if count > 1: print" {} --> {}".format(i, count) while alphaList.count(i) > 1: #weeding tested alpha alphaList.remove(i) </code> call function with your string as argument e.g counter("pEpper62532622" ![]() That's all... can download attachment or visit link below if code is not well formatted... https://gist.github.com/nny326/93d34e5d63b023d17aa5fa4534a9fb4a#file-duplicatecounter-py
|
![]() |
swiz2:How much? |
![]() |
ruphytelecom: Still available? If yes, how much? |
(1) (of 1 pages)
(Go Up)
Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health religion celebs tv-movies music-radio literature webmasters programming techmarket Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10) Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 7 |