top of page
learn_data_science.jpg

Data Scientist Program

 

Free Online Data Science Training for Complete Beginners.
 


No prior coding knowledge required!

Character Locator in Python

Writer's picture: Mariam AhmedMariam Ahmed

Given a string and a character, your task is to locate the positions of that character in the string. These types of problems are very competitive programming!


The first thing we need to ask the user about String & Character

string = input("Enter a string: ")
char   = input("Enter the character you want to locate: ")

Then by for loop, we go to each character in the string to check if it is the character we want or not, once it is true, we add the index of that character in the string as a position

char_locations = []

for x in range(len(string)):
    if string[x].lower() == char.lower():
        char_locations.append(x)

The output will be:

print(char_locations)
Enter a string: Mariam Ahmed
Enter the character you want to locate: a
[1, 4, 7]

That's it, I hope this article was worth reading and helped you acquire new knowledge no matter how small.


Feel free to check up on the notebook. You can find the results of code samples in this post.

0 comments

Recent Posts

See All

Comments


COURSES, PROGRAMS & CERTIFICATIONS

 

Advanced Business Analytics Specialization

Applied Data Science with Python (University of Michigan)

Data Analyst Professional Certificate (IBM)

Data Science Professional Certificate (IBM)

Data Science Specialization (John Hopkins University)

Data Science with Python Certification Training 

Data Scientist Career Path

Data Scientist Nano Degree Program

Data Scientist Program

Deep Learning Specialization

Machine Learning Course (Andrew Ng @ Stanford)

Machine Learning, Data Science and Deep Learning

Machine Learning Specialization (University of Washington)

Master Python for Data Science

Mathematics for Machine Learning (Imperial College London)

Programming with Python

Python for Everybody Specialization (University of Michigan)

Python Machine Learning Certification Training

Reinforcement Learning Specialization (University of Alberta)

Join our mailing list

Data Insight participates in affiliate programs and may sometimes get a commission through purchases made through our links without any additional cost to our visitors.

bottom of page