Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Class notes

XSADFSGRDTHFYJGUKFHIGLJH;K

Rating
-
Sold
-
Pages
2
Uploaded on
12-12-2023
Written in
2023/2024

sXACDVFBGTRHYTJUYKIU,LI.;

Institution
Course

Content preview

Remove special symbols / punctuation from a string
Given:
str1 = "/*Jon is @developer & musician"
Expected Output:
"Jon is developer musician"
Solution 1: Use string functions translate() and maketrans().
The string.punctuation constant contain all special symbols.
import string

str1 = "/*Jon is @developer & musician"
print("Original string is ", str1)

new_str = str1.translate(str.maketrans('', '', string.punctuation))

print("New string is ", new_str)

Solution 2: Using regex replace pattern in a string
import re

str1 = "/*Jon is @developer & musician"
print("Original string is ", str1)

# replace special symbols with ''
res = re.sub(r'[^\w\s]', '', str1)
print("New string is ", res)
Removal all characters from a string except integers
Given:
str1 = 'I am 25 years and 10 months old'
Expected Output:
2510
str1 = 'I am 25 years and 10 months old'
print("Original string is", str1)

# Retain Numbers in String
# Using list comprehension + join() + isdigit()
res = "".join([item for item in str1 if item.isdigit()])

print(res)
Write a program to find words with both alphabets and numbers from an input string.
Given:
str1 = "Emma25 is Data scientist50 and AI Expert"
Expected Output:
Emma25
scientist50
str1 = "Emma25 is Data scientist50 and AI Expert"
print("The original string is : " + str1)

res = []
# split string on whitespace
temp = str1.split()

Written for

Institution
Course
Unknown

Document information

Uploaded on
December 12, 2023
Number of pages
2
Written in
2023/2024
Type
Class notes
Professor(s)
Archana t
Contains
All classes

Subjects

$8.99
Get access to the full document:

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Get to know the seller
Seller avatar
sachienn

Get to know the seller

Seller avatar
sachienn vellore institution of technology
Follow You need to be logged in order to follow users or courses
Sold
-
Member since
2 year
Number of followers
0
Documents
11
Last sold
-

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions