Saturday, December 29, 2018

Python Ninja Bootcamp 41- Q&A 7th

Learn Python like a Professional! Take You from 0 to Hero






In this Python lecture, we will learn about the  Q&A 7th


Q. Write the Program to count the occurrence of a number in the digit given by the user
Example: 
111122233333


Output: 
1 occur 4-times
2 occur 3-times
3 occur 5-times


num=input('Enter the digit =')
>> Enter the digit = 111122233333

from collections import Counter

for key,value in Counter(list(num)).items():
    print('{x} occur {y}-times'.format(x=key,y=value))
>>1 occur 4-times
2 occur 3-times
3 occur 5-times

Q. Write a program to remove the punctuation marks from the string given by the user

Example: Hi guys, welcome back to python ninja bootcamp. Let's get started!

Output: Hi guys welcome back to python ninja bootcamp Let s get started


import re
pattern='\w+'
string=input('Enter the string = ')
>>Enter the string = Hi guys,welcome back to python ninja bootcamp. Let's get started!

' '.join(re.findall(pattern,string))
>> 'Hi guys welcome back to python ninja bootcamp Let s get started'


Q.Write a program to extract the Email id from the string given by the user.

Example: Please contact sn.gurukul24.7uk@gmail.com for assistance
Output: sn.gurukul24.7uk@gmail.com

import re
pattern='[\w\.-]+@[\w\.-]+' #[\w\.-]+ matches one or more aplha numeric, dot or dash
string=input('Enter the string = ')
>> Enter the string = Please contact sn.gurukul24.7uk@gmail.com for assistance

re.search(pattern,string).group()
>> 'sn.gurukul24.7uk@gmail.com'



EDITS ARE WELCOMED!!

In the next Blog, we will discuss Free Python Certification  

https://sngurukuls247.blogspot.com/2019/01/free-python-certification-online.html

......................................................................................................................................

Follow the link below to access Free Python Lectures-
https://www.youtube.com/channel/UCENc9qI7_r8KMf6-_1R1xnw

Instagram-
https://www.instagram.com/python.india/

View the Jupyter Notebook for this lecture

Download the Jupyter Notebook for this lecture 



Feel free contact me on-
Email - sn.gurukul24.7uk@gmail.com

No comments:

Post a Comment