Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Jython/Python
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
Jython/Python
Using "IN" for a string to find out how many of a certain letter...?
Patrick De
Ranch Hand
Posts: 133
posted 7 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
I was wondering if there is a way to use the IN command to find out "how many" of a certain letter are in a
string
.
Here is the code so far:
s = ("hello") user = str(input("What letter do you want?")) if str(user) in str(s): print ("You got a letter!") #if int(user) > 1: #more than one letter? # print("there are two of them!") else: print ("nope, no letter yet")
I know this doesn't work, but just wondering if there is a way of accomplishing this in a similar way.
Karthik Shiraly
Bartender
Posts: 1210
25
I like...
posted 7 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
s.count(
letter
)
Cj Kasper
Greenhorn
Posts: 1
posted 7 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
To expand upon Karthik Shiraly's answer you can also do this to account for case:
s.lower().count(<search ltr>)
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
User Input
Morse Code and Binary Trees
array confusion
Java Beginner Help: Sentinel Controlled Loop
Fresh Meat - Extremely Simple Numerology Word Processing Program - Assistance Requested!
More...