I have a text I want to search for all it's upper case letters, then present these letters unique and sorted. I welcome any suggestions.
sneekula
969
Nearly a Posting Maven
Recommended Answers
Jump to PostHere's an exampmle:
alphabet = "abcdefghijklmnopqrstuvwxyz" text1 = "LQZYdMDHPEdWOAVUCBDdsfTEFgdfGIRKwerJMSONPX" text2 = "" upper_letters = [] #P for letter in text1: # Check to see if the letter is already in upper_letters if upper_letters.count(letter) == 1: continue # If letter is uppercase, add it to upper_letters if letter …
Jump to PostYou can use Python's regular expression module re, very powerful for text processing, but there is a somewhat steep learning curve ahead!
# exploring Python's regular expression module re import re # find all upper case letters in a text: text = "This text has Upper and …
Jump to PostOr if regular expressions are too painful, some kind of compromise:
def count_caps(s): d = {} caps = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" for i in caps: d[i] = s.count(i) return d def print_caps(s): d = count_caps(s) # not 'for i in d' becuase dictionaries don't have guaranteed order for i …
All 9 Replies

Mouche
vegaseat
1,735
DaniWeb's Hypocrite
Team Colleague
jrcagle
77
Practically a Master Poster
sneekula
969
Nearly a Posting Maven
Ene Uran
638
Posting Virtuoso

Mouche
vegaseat
1,735
DaniWeb's Hypocrite
Team Colleague
sneekula
969
Nearly a Posting Maven
twekberg
0
Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.