String problem solving :: Python programming (2024)

Class Objectives

  • Practice problem solving in string data types.
  • Learn how to interpret real world problem into computer problem
  • More flexible usage of loops and conditionals
  • Dive deeper to string data structure
  • Process large and multi-dimensional string data in practice

Problems

  • Loop through strings
  • Character sorting
  • Type check
  • String reverse
  • Add suffix to string

Loop through strings

Requirements

Given a string consists of repeated characters. Write a function to process the string to return number of repeated characters in a dictionary.

  • Not allowed to use string.count(character) function
  • Your are encouraged to solve the problem with algorithms

Input:

string = "The more that you read, the more things you will know, the more that you learn, the more places you willl go."

Output:

{'T': 1, 'h': 7, 'e': 11, ' ': 21, 'm': 4, 'o': 10, 'r': 6, 't': 8, 'a': 5, 'y': 4, 'u': 4, 'd': 1, ',': 3, 'i': 3, 'n': 3, 'g': 2, 's': 2, 'w': 3, 'l': 7, 'k': 1, 'p': 1, 'c': 1, '.': 1}

Problem solving pattern

  • Step 1: Define a function with a parameter
  • Step 2: Define a dictionary
  • Step 3: Loop through the string
  • Step 4: Get keys of dictionary. keys = dict.keys() returns a list of keys
  • Step 5: Check if each character in the string exists in the keys.
  • Step 6: If it exists in the keys, increment it’s value by 1, if not assign a value 1.

Character sorting

Requirements

Given a string of random characters. Write a function to sort them in English alphabatical order.

  • Noe allowed to use Python sort functions
  • Solve the problem with algorithms

Problem solving pattern

Input:

string = 'dsajlvwjeoijvdskavljwioenvjskdlahj'

Output:

aaadddeehiijjjjjjkklllnoosssvvvvww

Hint

  • You may consider Python chr() and ord()

Type check

Requirements

Given string of random letters, digits and symbols. Write a function to return them in different lists.

  • You are encouraged to use regex

Input:

import re string = 'fjsdlkajlv463247836ewiFJKS&*$^&#$JFIEfjdksljVLWEJKjdkfjkd'

Output:

['f', 'j', 's', 'd', 'l', 'k', 'a', 'j', 'l', 'v', 'e', 'w', 'i', 'F', 'J', 'K', 'S', 'J', 'F', 'I', 'E', 'f', 'j', 'd', 'k', 's', 'l', 'j', 'V', 'L', 'W', 'E', 'J', 'K', 'j', 'd', 'k', 'f', 'j', 'k', 'd']['4', '6', '3', '2', '4', '7', '8', '3', '6']['&', '*', '$', '^', '&', '#', '$']

Problem solving pattern

  • Loop through the string by characters
  • Check each character if it is the type of letters, digits or symbols.
  • Return each list of result

String reverse

Requirements

Write a function to reverse a given string.

  • Your are encouraged to use algorithms
  • Not allowed to Python embedded reverse functions

Input:

string = "Children must be raught how to think, not what to think"

Output:

"kniht ot tahw ton ,kniht ot woh thguar eb tsum nerdlihC"

Problem solving pattern

  • Step 1: Define a function with a parameter
  • Step 2: Define a empty string variable
  • Step 3: Loop through the string with for loop
  • Step 4: Get the characters from the end until the beginning.
  • Step 5: Add each character into the result string

Add suffix to string

Requirements

Given a string consists of different words end with ing. Write a function to append ly to words end with ing, and ing to those are not end with ing, ignore those already are end with ly.

  • Not allowed to use Python endswith()
  • You are encouraged to use algorithms

Input:

string = "He is fully absessed with eating. Eating and eating, don't stop forever!"

Output:

"Heing ising fully absesseding withing eatingly. Eatingly anding eatingly, don'ting stoping forever!ing"

Problem solving pattern

  • Step 1: Write a function with a parameter
  • Step 2: Loop through the string to get each word
  • Step 3: Check if each word ends with ing or ly by splitting the word
  • Step 4: Add each word appropriate suffix and return the result
String problem solving :: Python programming (2024)
Top Articles
OpenAI ERC (OPENAI ERC) Price Prediction 2024, 2025–2030 | CoinCodex
Artist Copyrights
Craftsman M230 Lawn Mower Oil Change
Archived Obituaries
From Algeria to Uzbekistan-These Are the Top Baby Names Around the World
Fully Enclosed IP20 Interface Modules To Ensure Safety In Industrial Environment
Die Windows GDI+ (Teil 1)
Top Financial Advisors in the U.S.
30% OFF Jellycat Promo Code - September 2024 (*NEW*)
Poplar | Genus, Description, Major Species, & Facts
Doby's Funeral Home Obituaries
Crazybowie_15 tit*
Compare the Samsung Galaxy S24 - 256GB - Cobalt Violet vs Apple iPhone 16 Pro - 128GB - Desert Titanium | AT&T
Classroom 6x: A Game Changer In The Educational Landscape
Hoe kom ik bij mijn medische gegevens van de huisarts? - HKN Huisartsen
Mflwer
Keck Healthstream
Cvs El Salido
Xsensual Portland
How Long After Dayquil Can I Take Benadryl
Klsports Complex Belmont Photos
Waters Funeral Home Vandalia Obituaries
Craigslist Comes Clean: No More 'Adult Services,' Ever
Stephanie Bowe Downey Ca
Taylored Services Hardeeville Sc
Toonkor211
Past Weather by Zip Code - Data Table
Amazing Lash Bay Colony
Mia Malkova Bio, Net Worth, Age & More - Magzica
Have you seen this child? Caroline Victoria Teague
NIST Special Publication (SP) 800-37 Rev. 2 (Withdrawn), Risk Management Framework for Information Systems and Organizations: A System Life Cycle Approach for Security and Privacy
Flixtor Nu Not Working
The Venus Flytrap: A Complete Care Guide
Roto-Rooter Plumbing and Drain Service hiring General Manager in Cincinnati Metropolitan Area | LinkedIn
Austin Automotive Buda
Ishow Speed Dick Leak
My.lifeway.come/Redeem
Craigslist Jobs Brownsville Tx
Topos De Bolos Engraçados
Verizon Outage Cuyahoga Falls Ohio
Noaa Duluth Mn
RECAP: Resilient Football rallies to claim rollercoaster 24-21 victory over Clarion - Shippensburg University Athletics
Three V Plymouth
Sig Mlok Bayonet Mount
Kb Home The Overlook At Medio Creek
QVC hosts Carolyn Gracie, Dan Hughes among 400 laid off by network's parent company
9:00 A.m. Cdt
Stephen Dilbeck, The First Hicks Baby: 5 Fast Facts You Need to Know
Mail2World Sign Up
Besoldungstabellen | Niedersächsisches Landesamt für Bezüge und Versorgung (NLBV)
Salem witch trials - Hysteria, Accusations, Executions
Latest Posts
Article information

Author: Dean Jakubowski Ret

Last Updated:

Views: 6797

Rating: 5 / 5 (50 voted)

Reviews: 81% of readers found this page helpful

Author information

Name: Dean Jakubowski Ret

Birthday: 1996-05-10

Address: Apt. 425 4346 Santiago Islands, Shariside, AK 38830-1874

Phone: +96313309894162

Job: Legacy Sales Designer

Hobby: Baseball, Wood carving, Candle making, Jigsaw puzzles, Lacemaking, Parkour, Drawing

Introduction: My name is Dean Jakubowski Ret, I am a enthusiastic, friendly, homely, handsome, zealous, brainy, elegant person who loves writing and wants to share my knowledge and understanding with you.