<jupyter_start><jupyter_text>SET 13 Structured Programming Using Python                                                                                                          **DONE BY:                                                                                                         <NAME>                                                                                                         RA1911026010029                                                                                                         CSE-AIML**  1. **Write code that starts with a string of words and results in a newstring consisting of the same words, but where the first word swapsplaces with the second, and so on. For example, "the cat sat on themat" will be converted into "cat the on sat mat the".** *METHOD-1*<jupyter_code>#PROBLEM-1
#method-1
def func0029(stri):
    list1=[]
    list1=stri.split(" ")
    for i in range(0,len(list1)-1,2):
        list1[i],list1[i+1]=list1[i+1],list1[i]
    p=" ".join(list1)
    print(p)

print("Input :")
s10029=input("Enter the string :\n")
print("\033[1mOutput :")
func0029(s10029)<jupyter_output>Input :
Enter the string :
the cat sat on the mat
[1mOutput :
cat the on sat mat the<jupyter_text>*METHOD-2*<jupyter_code>#PROBLEM-1
#method-2
list0029 = [] 
n0029 = int(input("Enter number of elements : ")) 
for i in range(0, n0029): 
    e0029 = (input())
    list0029.append(e0029) 
      
def swap_pairs(list0029):
    for i in range(0, len(list0029)-1, 2):
        list0029[i], list0029[i+1] = list0029[i+1], list0029[i]
   
swap_pairs(list0029)
print("\033[1mOutput : ")
print(" ".join(list0029))<jupyter_output>Enter number of elements : 6
the
cat
sat
on
the
mat
[1mOutput : 
cat the on sat mat the<jupyter_text>2.**Write a function that takes a list of words (containing duplicates) andreturns a list of words (with no duplicates) sorted by decreasingfrequency. E.g. if the input list contained 10 instances of theword table and 9 instances of the word chair, then table would appearbefore chair in the output list.**<jupyter_code>#PROBLEM-2
list0029 =[]
n0029 = int(input("Enter number of elements : ")) 

for i in range(0, n0029): 
    e0029 = input() 
    list0029.append(e0029) 
    
print("The original list : " +", ".join(list0029))  

ans = sorted(set(list0029), key = lambda e0029: list0029.count(e0029), reverse = True)
print("The required list : " + ", ".join(ans))<jupyter_output>Enter number of elements : 4
chair
chair
chair
table
The original list : chair, chair, chair, table
The required list : chair, table<jupyter_text>3.**Write code that removes whitespace at the beginning and end of astring, and normalizes whitespace between words to be a singlespace character.**<jupyter_code>#PROBLEM-3
s0029 = '   this is my  sentence that starts and ends    with whitespace '
s0029 = s0029.split(' ')
s0029 = [word.strip() for word in s0029 if word]
s0029 = ' '.join(s0029)
print(s0029)<jupyter_output>this is my sentence that starts and ends with whitespace<jupyter_text>4.**Write code to initialize a two-dimensional array of setscalled word_vowels and process a list of words, adding each wordto word_vowels[l][v] in ascending order of l, where l is the length of theword and v is the number of vowels it contains.**<jupyter_code>#PROBLEM-4
m0029, n0029 = 6,10
word_vowels = [[set() for j in range(m0029)] for i in range(n0029)]
sent = ['orange', 'apple', 'cucumber', 'chocolate', 'pear', 'cashew']
for lis in word_vowels:
    for word in sent:
        v = 0
        l = len(word)
        for letter in word: 
            if letter in "aeiou":
                v += 1
        word_vowels[l][v] = word

for line in word_vowels:
    print(*line)<jupyter_output>set() set() set() set() set() set()
set() set() set() set() set() set()
set() set() set() set() set() set()
set() set() set() set() set() set()
set() set() pear set() set() set()
set() set() apple set() set() set()
set() set() cashew orange set() set()
set() set() set() set() set() set()
set() set() set() cucumber set() set()
set() set() set() set() chocolate set()<jupyter_text>5.**Assign a new value to sentence, namely the string ’she sells sea shells by the seashore’, then write code to perform the following tasks: a) Print all words beginningwith ’sh’: b) Print all words longer than 4 characters.**<jupyter_code># PROBLEM-5.1
str0029 = input("Enter the string :\n")
print("\033[1mThe words starting with 'sh' : ")
for i in str0029.split():
    if i.startswith("sh"):
        print(i)
#PROBLEM-5.2
def strin0029(str):
    string = [] 
    text = str.split(" ") 
    for x in text: 
        if len(x) > 4: 
            string.append(x) 
    return " ,".join(string) 

str29 =input("Enter the string :\n")
print("\033[1mPrinting the words with length greater than 4...")
print(strin0029(str29))<jupyter_output>Enter the string :
she sells sea shells by the sea shore
[1mPrinting the words with length greater than 4...
sells ,shells ,shore
{'fraction_non_alphanumeric': 0.12157258064516129, 'fraction_numerical': 0.054838709677419356, 'mean_word_length': 2.7986217457886675, 'pattern_counts': {'":': 1, '<': 20, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 20, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '466811', 'license': 'MIT', 'n_tokens_mistral': 1758, 'n_tokens_neox': 1549, 'n_words': 551, 'path': 'WEEK-1.ipynb', 'repo_name': 'thejaswin123/APP_lab', 'size': '4965'}