Professional Documents
Culture Documents
1
1
/bin/python3
""" Get the first 70 characters from word1, reverse the strings, save it in
variable rword2, and print it"""
#creating the variable to store the data first and then loop through in reverse
rword2 = word1[:70] # saving only the first 70 characters
rword2 = rword2[::-1] # reversing the characters
print(rword2)
""" Remove all the wide spaces from rword2, join the characters using the
special character specified in special2, and print the joint string"""
rword2_no_spaces = rword2.replace(' ', '') # replacing the spaces first with
nothing
joint_string = special2.join(rword2_no_spaces)
print(joint_string)
""" If every string from list1 is present in para, then format the **print**
statement as follows: 'Every string in {list1} were present', else:
'Every string in {list1} were not present'"""
# Method 1 using the flag method
all_strings_present = True
for strings in list1:
if strings not in para:
all_strings_present = False # when we find the first element that's not
present in para, we can stop looking, otherwise we continue
break
# Now we check if the flag remains true or not
if all_strings_present == True:
print(f'Every string in {list1} were present')
else:
print(f'Every string in {list1} were not present')
"""# Method 2 checking the if all the words were present in para or not
# We define a counter to check at the end if it's equal to the len of the list
counter = 0
# We begin the loop to check every string inside list1
for strings in list1:
if (strings in para):
counter += 1 # the string was inside para
else:
counter += 0 # the string was not inside para
""" Split every word from word1 and print the first 20 strings as a list"""
# we first split the words from word1 into a list to separate everything
list_of_words = word1.split() # create the list with all the words separated
first_20_words = list_of_words[:20] # only the first 20
print(first_20_words)
""" Calculate the less frequently used words whose count < 13. Print the last
20 less frequent words as a list. Note, count the words in the order they appear"""
# We create a list to store the less frequent words
less_frequent_words = [] # empty list to add to
for strings in list_of_words:
if word1.count(strings) < 13:
if strings not in less_frequent_words:
less_frequent_words.append(strings)
# Now we select only the last 20 less frequent words from the list
print(less_frequent_words[-20:]) # 20th word is the -19th in the index, hence
the -20 to select it
""" Print the last index in word1, where the substring **strfind** is found"""
# We can use rfind or rindex. The difference being that using rfind and not
finding the sub-string returns a -1, while rindex() returns a ValueError exception
print(word1.rfind(strfind))
if __name__ == '__main__':
para = input()
spch1 = input()
spch2 = input()
qw1_count = int(input().strip())
qw1 = []
for _ in range(qw1_count):
qw1_item = input()
qw1.append(qw1_item)
strf = input()