0% found this document useful (0 votes)
58 views

Python

The code defines a stringmethod function that takes a paragraph string and performs various string operations on it like replacing characters, reversing strings, splitting into lists, and checking for substring matches. It also counts word frequencies and prints the least frequent words. The function manipulates the input strings and lists in various ways, such as replacing, joining, finding, and slicing, to perform the described string operations.
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)
58 views

Python

The code defines a stringmethod function that takes a paragraph string and performs various string operations on it like replacing characters, reversing strings, splitting into lists, and checking for substring matches. It also counts word frequencies and prints the least frequent words. The function manipulates the input strings and lists in various ways, such as replacing, joining, finding, and slicing, to perform the described string operations.
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/ 2

sp = iter(special1)

for i in sp:
para = para.replace(i, "")
word1 = para

st = word1[0:70]
rword2 = st[::-1]
print(rword2)

rword2 = rword2.replace(" ", "")


rword2 = special2.join(rword2)
print(rword2)

count = 0
for i in list1:
if (i in para):
count = count + 1
else:
pass
if (count > 0):
print("Every string in " + str(list1) + " were present")
else:
print("Every string in " + str(list1) + " were not present")

word1_list = list(word1.split(" "))


word2 = word1_list[0:20]
print(word2)

x = []
for i in word1_list:
if word1_list.count(i) < 3 and i not in x:
x.append(i)
print(x[-20:])

print(para.rfind(strfind))

Python 3 - Functions and OOPs_FP1. hands on python string methods## Complete the
'strmethod' function below.## The function accepts following parameters:# 1. STRING
para# 2. STRING spch1# 3. STRING spch2# 4. LIST li1# 5. STRING strf#def
stringmethod(para, special1, special2, list1, strfind):for myChar in special1:para
= para.replace(myChar,"")word1=pararword2=word1[69::-
1]print(rword2)myspaceremove=rword2.replace(" ",
"")myspaceremove=myspaceremove.replace(" ", "")myword=
special2.join(myspaceremove)print(myword)if all(SearchStr in para for SearchStr in
list1):print("Every string in %s were present" %list1)else:print("Every string in
%s were not present" %list1)number=word1splitAll =
number.split()print(splitAll[0:20])mylist=[]myDict = dict()for t in
splitAll:myDict[t]=myDict.get(t,0)+1for x,y in
myDict.items():if(y<3):mylist.append(x)print(mylist[-
20:])print(word1.rfind(strfind))

def stringmethod(para, special1, special2, list1, strfind):


for myChar in special1:
para = para.replace(myChar,"")
word1=para

rword2=word1[69::-1]
print(rword2)

myspaceremove=rword2.replace(" ", "")


myspaceremove=myspaceremove.replace(" ", "")
myword= special2.join(myspaceremove)
print(myword)
if all(SearchStr in para for SearchStr in list1):
print("Every string in %s were present" %list1)
else:
print("Every string in %s were not present" %list1)
number=word1
splitAll = number.split()
print(splitAll[0:20])
mylist=[]
myDict = dict()
for t in splitAll:
myDict[t]=myDict.get(t,0)+1
for x,y in myDict.items():
if(y<3):
mylist.append(x)
print(mylist[-20:])
print(word1.rfind(strfind))

x = 0
for i in range(2,num):
if(len([j for j in range(2,i-1) if i%j==0]) == 0):
x = x + 1
if(int(val) == 0):
if (x % 2) == 0:
yield i
if(int(val) == 1):
if (x % 2) != 0:
yield i

You might also like