100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached
logo-home
rwtyukjthbgrfvcdwefwrgthyuj $8.99   Add to cart

Class notes

rwtyukjthbgrfvcdwefwrgthyuj

 0 view  0 purchase
  • Course
  • Institution

asdtfrgyhujhnmbfgvfgtrhyjuedfrgtyjukie

Preview 1 out of 2  pages

  • December 12, 2023
  • 2
  • 2023/2024
  • Class notes
  • Archana t
  • All classes
  • Unknown
avatar-seller
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()

The benefits of buying summaries with Stuvia:

Guaranteed quality through customer reviews

Guaranteed quality through customer reviews

Stuvia customers have reviewed more than 700,000 summaries. This how you know that you are buying the best documents.

Quick and easy check-out

Quick and easy check-out

You can quickly pay through credit card or Stuvia-credit for the summaries. There is no membership needed.

Focus on what matters

Focus on what matters

Your fellow students write the study notes themselves, which is why the documents are always reliable and up-to-date. This ensures you quickly get to the core!

Frequently asked questions

What do I get when I buy this document?

You get a PDF, available immediately after your purchase. The purchased document is accessible anytime, anywhere and indefinitely through your profile.

Satisfaction guarantee: how does it work?

Our satisfaction guarantee ensures that you always find a study document that suits you well. You fill out a form, and our customer service team takes care of the rest.

Who am I buying these notes from?

Stuvia is a marketplace, so you are not buying this document from us, but from seller sachienn. Stuvia facilitates payment to the seller.

Will I be stuck with a subscription?

No, you only buy these notes for $8.99. You're not tied to anything after your purchase.

Can Stuvia be trusted?

4.6 stars on Google & Trustpilot (+1000 reviews)

79223 documents were sold in the last 30 days

Founded in 2010, the go-to place to buy study notes for 14 years now

Start selling
$8.99
  • (0)
  Add to cart