<jupyter_start><jupyter_text>Q1. Write a Python program to get the string from the given string whereall the occurrence of its first char has been changed to '$,' except firstchar itself?    Sample String: 'prospect'    Expected Result : 'pros$ect'<jupyter_code>def change_char(str):
    first_char = str[0]
    str = str.replace(first_char,'$')
    str = first_char + str[1:]
    return str
    
Sample_string = 'prospect'
Expected_result = change_char(Sample_string)
print(Expected_result)<jupyter_output>pros$ect<jupyter_text>Q2. Write a Python program to get the single string from the two givenstrings, and separated by the space and swap the first two characters ofeach string?    Sample String : 'abc', 'xyz'.    Expected Result: 'xyc abz'<jupyter_code>def swap_char(str1,str2):
    new_str1 = str2[:2] + str1[2:]
    new_str2 = str1[:2] + str2[2:]
    result = new_str1 + " " + new_str2
    print(f'Expected result: {result}')
swap_char('abc', 'xyz')<jupyter_output>Expected result: xyc abz<jupyter_text>Q3. Write the Python program to add 'ing' at the end of the given string(length of the string should be at least 3). If given string already endswith 'ing,' then add 'ly' instead. If string length of the given string is lessthan 3, leave it unchanged?    Sample string: ' abc '    Expected result: ' abcing '    Sample string: ' string '    Expected result: ' stringly '<jupyter_code>def add_str(str):
    if len(str) < 3:
        print(f'As the string length is less than 3 so expected result {str}')
    else:
        if str[-3:] == 'ing':
            new_str = str + 'ly'
            print(f'Expected result: {new_str}')
        else:
            new_str = str + 'ing'
            print(f'Expected result: {new_str}')
add_str('abc')
add_str('string')<jupyter_output>Expected result: abcing
Expected result: stringly<jupyter_text>Q4. Write the Python program to find the first appearance of thesubstring 'not' and 'poor' from the given string, if 'not' follows the 'poor',replace the whole 'not'...' poor' substring with 'good'.Return the resultingstring.    Sample string: 'The lyrics are not that poor!'    'The lyrics are poor!'    Expected Result: 'The lyrics are good!'    'The lyrics are poor!'<jupyter_code>def replace_str(str1):
    not_1 = str1.find('not')
    poor_1 = str1.find('poor')
    
    if poor_1 > not_1 and poor_1 > 0 and not_1 > 0:
        str1 = str1.replace(str1[not_1:(poor_1 + 4)], 'good')
        print(f'Expected result: {str1}')
    else:
        print(f'Expected result: {str1}')
        
replace_str('The lyrics is not that poor!')
replace_str('The lyrics is poor!')<jupyter_output>Expected result: The lyrics is good!
Expected result: The lyrics is poor!<jupyter_text>Q5. Write the Python program to remove the characters which have oddindex values of a given string.<jupyter_code>def rem_odd_char(str):
    return "".join(str[index] for index in range(len(str)) if index%2 != 0 )

#Example
print(rem_odd_char('characters'))<jupyter_output>hrces<jupyter_text>Q6. Write the python program to print the following floating numbers upto 2 decimal places?<jupyter_code>def two_decimals(number):
    return float('{:.2f}'.format(number))

#Example
two_decimals(3.14576)<jupyter_output><empty_output><jupyter_text>Q7. Write the Python program to format a number with a percentage?<jupyter_code>def format_num(number):
    return (f'{number}%')

print(format_num(200))<jupyter_output>200%<jupyter_text>Q8. Write the Python program to count occurrences of a substring in aString?<jupyter_code>def count_str(string,sub_string):
    print(string.count(sub_string))
string = 'A quick brown fox jumps over the lazy dog.'
sub_string = 'A'
count_str(string,sub_string)<jupyter_output>1<jupyter_text>Q9. Write the Python program to count repeated characters in a string.    Sample string: ' thequickbrownjumpsoverthelazydog '        Expected output:    o 3    e 3    u 2    h 2    r 2    t 2<jupyter_code>from collections import defaultdict
str1 = 'thequickbrownfoxjumpsoverthelazydog'
d = defaultdict(int)
for c in str1:
    d[c] += 1
    
for c in sorted(d, key = d.get, reverse = True):
    if d[c]>1:
        print(f'{c} {d[c]}')<jupyter_output>o 4
e 3
t 2
h 2
u 2
r 2<jupyter_text>Q10. Write the Python program to print the square and cube symbol inthe area of a rectangle and volume of a cylinder?    Sample outputThe area of the rectangle is 1256.66cm2    The volume of the cylinder is 1254.725cm3<jupyter_code>def square(num):
    print(f'The area of rectangle is {num}cm\u00b2')
    
    
def cube(num):
    print(f'The volume of cylinder is {num}cm\u00b3')
    
#Examples
square(1256.66)
cube(1254.725)<jupyter_output>The area of rectangle is 1256.66cm²
The volume of cylinder is 1254.725cm³<jupyter_text>Q11. Write the Python program to check if a string contains all letters ofthe alphabet?<jupyter_code>def all_alphabets(str1):
    contain_all_alphabets = True
    for char in 'ABCDEFGHIJKLMNOPQRSTUVWXYZ':
        if char not in str1.upper():
            contain_all_alphabets = False
            break
    print(f'{str1} contains all alphabets: {contain_all_alphabets}')
all_alphabets('abcdefghijklmnopqrstuvwxyz')
all_alphabets('abcdefghijklmnopqrstuvwxz')<jupyter_output>abcdefghijklmnopqrstuvwxyz contains all alphabets: True
abcdefghijklmnopqrstuvwxz contains all alphabets: False<jupyter_text>Q12. Write the Python program to find the second most repeated wordin a given string?<jupyter_code>import collections

_list_of_words = 'where there is a will thee is a way'.split()
_dict_repeated_words = {}
for i in range(len(_list_of_words)):
    word = _list_of_words[i]
    if word in _dict_repeated_words.keys():
        _dict_repeated_words[word] = _dict_repeated_words[word] + 1
    else:
        _dict_repeated_words[word] = 1
else:
    _dict_repeated_words = sorted(_dict_repeated_words.items(), key=lambda kv: kv[1])
    print(_dict_repeated_words[-2])<jupyter_output>('is', 2)<jupyter_text>Q13. Write the Python program to find the minimum window in the givenstring, which will contains all the characters of another givenstrings?    Example 1    Input : string1 = " PRWSOERIUSFK "    string2 = " OSU "    Output: Minimum window is "OERIUS"<jupyter_code># https://www.w3resource.com/python-exercises/string/python-data-type-string-exercise-74.php
import collections
def min_window(str1, str2):
    result_char, missing_char = collections.Counter(str2), len(str2)
    i = p = q = 0
    for j, c in enumerate(str1, 1):
        missing_char -= result_char[c] > 0
        result_char[c] -= 1
        if not missing_char:
            while i < q and result_char[str1[i]] < 0:
                result_char[str1[i]] += 1
                i += 1
            if not q or j - i <= q - p:
                p, q = i, j
    return str1[p:q]
str1 = "PRWSOERIUSFK"
str2 = "OSU"
print("Original Strings:\n",str1,"\n",str2)
print("Minimum window:")
print(min_window(str1,str2))<jupyter_output>Original Strings:
 PRWSOERIUSFK 
 OSU
Minimum window:
OERIUS<jupyter_text>Q14. Write the Python program to count number of substrings from agiven string of lowercase alphabets with exactly k distinct (given)characters?    Input a string (lowercase alphabets): wolf    Input k: 4    Number of substrings with exactly 4 distinct characters: 1<jupyter_code>def count_k_dist(str1, k): 
    str_len = len(str1) 
    result = 0
    ctr = [0] * 27
    for i in range(0, str_len): 
        dist_ctr = 0
        ctr = [0] * 27
        for j in range(i, str_len): 
            if(ctr[ord(str1[j]) - 97] == 0): 
                dist_ctr += 1
            ctr[ord(str1[j]) - 97] += 1
            if(dist_ctr == k): 
                result += 1 
            if(dist_ctr > k): 
                break
    return result
str1 = input("Input a string (lowercase alphabets):") 
k = int(input("Input k: "))

print("Number of substrings with exactly", k, "distinct characters : ", end = "") 
print(count_k_dist(str1, k))<jupyter_output>Input a string (lowercase alphabets):wolf
Input k: 4
Number of substrings with exactly 4 distinct characters : 1<jupyter_text>Q15. Write the Python program to count number of substrings with samefirst and last characters of the given string?    Input a string: abcd    4<jupyter_code>def countSubstringWithEqualEnds(s): 
  
    result = 0; 
    n = len(s); 
  
    # Iterating through all substrings in 
    # way so that we can find first and  
    # last character easily 
    for i in range(n): 
        for j in range(i, n): 
            if (s[i] == s[j]): 
                result = result + 1
  
    return result 
s = "abcd" 
print(countSubstringWithEqualEnds(s))<jupyter_output>4
{'fraction_non_alphanumeric': 0.10119392604613422, 'fraction_numerical': 0.024226266373014952, 'mean_word_length': 3.6865833785985878, 'pattern_counts': {'":': 0, '<': 51, '<?xml version=': 0, '>': 53, 'https://': 1, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '15', 'dir': 'jupyter-structured-clean-dedup', 'id': '572517', 'license': 'MIT', 'n_tokens_mistral': 3081, 'n_tokens_neox': 2891, 'n_words': 890, 'path': 'Deep Learning/Subjective Assignment - 1- Python core.ipynb', 'repo_name': 'deepchatterjeevns/Ineuron.ai', 'size': '8627'}