0% found this document useful (0 votes)
46 views3 pages

Python Case Study

The document contains examples of using Python to: 1) Perform set operations and print outputs; 2) Validate a password against multiple regex criteria; 3) Loop through and print list elements with their indexes; 4) Use slicing and other string methods to manipulate substrings; 5) Find the intersection and unique elements of two lists; 6) Generate random samples from a filtered list.

Uploaded by

debobroto32
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
46 views3 pages

Python Case Study

The document contains examples of using Python to: 1) Perform set operations and print outputs; 2) Validate a password against multiple regex criteria; 3) Loop through and print list elements with their indexes; 4) Use slicing and other string methods to manipulate substrings; 5) Find the intersection and unique elements of two lists; 6) Generate random samples from a filtered list.

Uploaded by

debobroto32
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

nums =set([1,1,2,3,3,3,4,4])

print(len(nums))
4

d ={"john":40, "peter":45}
print(list(d.keys()))
['john', 'peter']

import re
password = "Debobr$t1"
flag = 0
while True:
if (len(password)<6):
flag = -1
break
elif (len(password)>12):
flag = -1
break
elif not re.search("[a-z]", password):
flag = -1
break
elif not re.search("[A-Z]", password):
flag = -1
break
elif not re.search("[0-9]", password):
flag = -1
break
elif not re.search("[#@$]", password):
flag = -1
break
elif re.search("\s", password):
flag = -1
break
else:
flag = 0
print("Valid Password")
break
if flag ==-1:
print("Not a Valid Password")

a = [4,7,3,2,5,9]
for i in a:
print("Element: " + str(i) + " Index: "+ str(a.index(i)))
Element: 4 Index: 0
Element: 7 Index: 1
Element: 3 Index: 2
Element: 2 Index: 3
Element: 5 Index: 4
Element: 9 Index: 5

import re
input = "H1e2l3l4o5w6o7r8l9d"
str=input[0::2]
print(str)

Helloworld
import re
input = "rise to vote sir"
str=len(input)
str_new=input[len(input)::-1]
print(str_new)
ris etov ot esir

inputString = 'abcdefgabc'
#casefold() is to ensure that uppercase and lower case charachter is treated same.
#If you don't want, you can remove casefold()
tempStr = ''
for i in inputString:
if i not in tempStr:
print(i, ', ', inputString.count(i))
tempStr = tempStr+i
a , 2
b , 2
c , 2
d , 1
e , 1
f , 1
g , 1

list1 = [1,3,6,78,35,55]
list2 = [12,24,35,24,88,120,155]
intersection_set = set.intersection(set(list1), set(list2))
#find intersection of list1 and list2
intersection_list = list(intersection_set)
print(intersection_list)
[35]

def Remove(duplicate):
final_list = []
for num in duplicate:
if num not in final_list:
final_list.append(num)
return final_list
# Driver Code
duplicate = [2, 4, 10, 20, 5, 2, 20, 4]
print(Remove(duplicate))
[2, 4, 10, 20, 5]

list = [12,24,35,24,88,120,155]
[var for var in list if var != 24]
Out[32]: [12, 35, 88, 120, 155]

list = [12,24,35,70,88,120,155]
[var for var in list if list.index(var) !=0 and list.index(var) !=4 and
list.index(var) !=5 ]
Out[40]: [24, 35, 70, 155]

list = [12,24,35,70,88,120,155]
[var for var in list if var % 5 !=0 and var % 7 !=0]
Out[43]: [12, 24, 88]

import random
#x = random.sample(range(1,1000), 5)
x=range(1,1000)
mylist=[var for var in x if var % 5 ==0 or var % 7 ==0]
x=random.sample(mylist,5)
print(x)
[280, 915, 20, 45, 574]

num=5
newnum=0
for each in range(1,num+1):
newnum = newnum+(each/(each+1))

print("computed value : ",format(round(newnum,2)))

You might also like