This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pprint as p | |
#pprint is pretty printing module | |
message = 'hello how are you' count = { } | |
for character in message: | |
count.setdefault (character, 0) | |
count[character] = count[character] + 1 | |
p.pprint (count) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
birthday={'dev':'18 mar','deep':'18 mar','yash':'6 may'} | |
while True: | |
name=input('enter your name (enter to exit)') | |
if name=='': | |
break | |
if name in birthday: | |
print(name + ' birthday is at '+ birthday[name]) | |
else: | |
print('your name is not here ') | |
bday=input('what is your bday') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
passwords={'email':'game','facebook':'dev'} | |
import sys,pyperclip | |
if len(sys.argv) < 2: | |
print("enter proper argument") | |
sys.exit() | |
account=sys.argv[1] | |
if account in passwords: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
phonenumber=input('enter your phonenumber') | |
def isphonenumber(number): | |
if len(phonenumber) != 10: | |
return False | |
for i in range(0,10): | |
if not number[i].isdecimal(): | |
return False | |
return True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#check phonenumber using regular expression | |
import re | |
phonenumber=input('enter your phonenumber') | |
def checknumber(number): | |
phonenum=re.compile(r'\d\d\d\d\d\d\d\d\d\d') | |
mo=phonenum.search(number) | |
print('phonenumber found:'+mo.group()) | |
checknumber(phonenumber) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#aeiou character using regular expression | |
message=input('enter the message') | |
import re | |
def vowelslist(message): | |
vowelRegex=re.compile(r'[aeiouAEIOU]') | |
print(vowelRegex.findall('hello')) | |
vowelslist(message) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#consonantlist character using regular expression | |
message=input('enter the message') | |
import re | |
def consonantlist(message): | |
vowelRegex=re.compile(r'[^aeiouAEIOU]') | |
print(vowelRegex.findall('hello')) | |
vowelslist(message) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#os.path.join is used to create the string of filename | |
import os | |
myfiles=['account.txt','details.csv','invite.docx'] | |
for filename in myfiles: | |
print(os.path.join('C:\\Users\\asweigart',filename)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
print(os.getcwd()) | |
print(os.chdir('C:\\Windowns')) #chnage working directory |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
f=open("deep.txt") | |
#content=f.read() #it will read whole file content | |
#print(content) | |
print(f.readline()) #it will read only first line | |
print(f.readlines()) #it will read file in list |