Sitemap
Saro

Saro

Member-only story

Strings in Python [3]

4 min readDec 13, 2024

--

Hello,

Press enter or click to view image in full size
Photo by Hitesh Choudhary on Unsplash

71. Reverse Each Word in a String

python
Copy code
reversed_words = ' '.join(word[::-1] for word in "Hello World".split())  # 'olleH dlroW'

72. Find All Numeric Substrings

python
Copy code
import re
numeric_substrings = re.findall(r'\d+', "There are 123 apples and 456 oranges.") # ['123', '456']

73. Capitalize the First Letter of Each Sentence

python
Copy code
text = "hello world. this is python."
capitalized_sentences = '. '.join(sentence.capitalize() for sentence in text.split('. ')) # 'Hello world. This is python.'

74. Check if String Contains Only Hexadecimal Characters

python
Copy code
is_hex = lambda s: all(char in "0123456789abcdefABCDEF" for char in s)
result = is_hex("1A3F") # True

75. Extract Words Starting with a Specific Letter

python
Copy code

--

--