<jupyter_start><jupyter_text>Q1. Write a function using only list filter lambda that can tell whether a number is a Fibonacci number or not. You can use a pre-calculated list/dict to store fab numbers till 10000 PTS:100<jupyter_code>from functools import reduce

result = lambda n: reduce(lambda x, _: x+[x[-1] + x[-2]],range(n-2),[0,1])
c = (result(10000))

a = int(input("Enter number to check ? "))

print(f"Evaluating whether number {a} is a fibonacci ? {a in c}")<jupyter_output>Enter number to check ? 10
Evaluating whether number 10 is a fibonacci ? False<jupyter_text>Q2. Using list comprehension (and zip/lambda/etc if required) write five different expressions that: PTS:100    Add 2 iterables a and b such that a is even and b is odd    Strips every vowel from a string provided (tsai>>t s)    Acts like a ReLU function for a 1D array    Acts like a sigmoid function for a 1D array    Takes a small character string and shifts all characters by 5 (handle boundary conditions) tsai>>yxfn<jupyter_code>#Add 2 iterables a and b such that a is even and b is odd
a = range(20)
b = range(20)

result = list(map(sum,zip(filter(lambda x: x%2 ==0,a),filter(lambda y:y%2,b))))
print(result)<jupyter_output>[1, 5, 9, 13, 17, 21, 25, 29, 33, 37]<jupyter_text>Strips every vowel from a string provided (tsai>>t s)<jupyter_code>str = "tsai"
vowels = ["a","e","i","o","u"]
result = "".join([x for x in str.lower() if x not in vowels])
print(f"Result strip of word :: {str} >> {result}")<jupyter_output>Result strip of word :: tsai >> ts<jupyter_text>Acts like a ReLU function for a 1D array<jupyter_code>lst = [0,-1,1,5,-8,-7,-0.5,0.0,0.15,23]

# Using List Comprehension
result = [x if x >= 0 else 0 for x in lst]
print("List Comprehension: ", result)<jupyter_output>List Comprehension:  [0, 0, 1, 5, 0, 0, 0, 0.0, 0.15, 23]<jupyter_text>Acts like a sigmoid function for a 1D array<jupyter_code>import math
lst = [0,-1,1,5,-8,-7,-0.5,0.0,0.15,23]

result = [math.exp(x)/(math.exp(x)+1) for x in lst]
print(result)<jupyter_output>[0.5, 0.2689414213699951, 0.7310585786300049, 0.9933071490757152, 0.00033535013046647816, 0.0009110511944006454, 0.37754066879814546, 0.5, 0.5374298453437495, 0.9999999998973812]<jupyter_text>Takes a small character string and shifts all characters by 5 (handle boundary conditions) tsai>>yxfn<jupyter_code>import string

alphabets = string.ascii_lowercase
str = "tsai"

result = lambda str: "".join([alphabets[(alphabets.index(x) + 5) % len(alphabets)] for x in str])
print(result(str))<jupyter_output>yxfn<jupyter_text>Q3 A list comprehension expression that takes a ~200 word paragraph (write your own paragraph to check), and checks whether it has any of the swear words mentioned in https://github.com/RobertJGabriel/Google-profanity-words/blob/master/list.txt PTS:200<jupyter_code>!wget https://raw.githubusercontent.com/RobertJGabriel/Google-profanity-words/master/list.txt -O swear_words
with open("swear_words", "r") as file:
    swear_words = [x.strip() for x in file.readlines()]
#Checks if an word exist in paragraph
check_list = lambda paragraph : any([True for i in swear_words if i in paragraph])

# Returns a response with text displaying how many words found.
check_list1 = lambda paragraph: f"Text contains {len([True for w in swear_words if w in paragraph])} Swear Words." if len([True for w in swear_words if w in paragraph]) > 0 else "Text Does not contain any Swear words."

paragraph = """As the billionaire Mistry clan and the Tata conglomerate head for a bitter split, they are already preparing for their next battle: the value of a stake in Tata Sons Pvt., which is at the center of India’s biggest corporate feud.
The Mistry family-owned Shapoorji Pallonji Group holds 18.4% of the holding company of the software-to-trucks Tata empire, and wants to sell it and raise funds for its own cash-strapped businesses. It had previously sought to pledge the shares as collateral, but was blocked this week when Tata told the Supreme Court it was open to buying the stock itself if Mistrys needed money.
But the focus of the years-long dispute could now shift to what each party thinks is the fair valuation of the stake. While court filings peg it at more than 1.5 trillion rupees ($20.3 billion), the eventual deal value will depend on which side can drive a hard bargain.
The indebted SP Group, with upcoming debt maturities, may prefer a quick deal. Even at depressed valuations, it won’t be easy for the Tata Group or any other investor to fork out such a sum at a time when many economies, including India’s, have been ravaged by the coronavirus pandemic.
“The parting of ways will lie in the details as it is not clear they will quickly agree to a valuation,” said <NAME>, founder of proxy advisory firm InGovern Research Services Pvt. in Bangalore. “Additionally, Tata group is in no hurry while the SP group is hard-pressed for funding.”.
Easy exit For outside investors, the initial charm of buying into the holding company of the $113 billion conglomerate quickly fades when they see Tata Sons is closely held. The lack of an easy exit may make it less appealing to private equity investors or sovereign funds that keep a sharp eye on returns.
Any stakeholder in Tata Sons, under the amended Articles of Association, may be first required to offer its equity to the Tatas before seeking out other investors, according to a person familiar with the matter and court documents.
Tata Sons declined to comment on the possible stake sale while SP Group did not offer any immediate comments.
The potential disagreement over the stake value is the latest chapter in a four-year-old wrangle that started with a boardroom coup in 2016 at Tata Sons. It led to the abrupt ouster of Cyrus Mistry as Tata Group chairman and sparked India’s biggest corporate battle. Cyrus, 52, is the son of billionaire Pallonji Mistry, 91, who controls the 155-year-old SP Group.
After succeeding Ratan Tata in 2012 as chairman of Tata Sons, Cyrus Mistry sought to reduce the conglomerate’s debt in ways that threatened to undo the legacy of the Tata patriarch — who spearheaded the purchases of Jaguar Land Rover and British steelmaker Corus Group — resulting in his removal.
Tata Trusts — a collective of charities headed by Tata Sons Chairman Emeritus Ratan Tata — owns 66% in Tata Sons but isn’t legally allowed to buy more shares on their own.
Tata, 82, is drawing up plans to seek out potential partners that could buy out the Mistry family’s stake in Tata Sons, people familiar with the matter said, asking not to be identified as the information is private.
Back in 2016, days after Cyrus Mistry’s removal, the Tata family trusts were assessing the interest of sovereign wealth funds and other long-term investors, but the Mistry family wasn’t keen to sell at the time, people familiar with the matter said then.
Despite the challenges, the possibility of the Tata stake sale has buoyed the stocks of SP Group’s listed firms. Sterling & Wilson Solar Ltd. has jumped 20% in Mumbai since the Mistry family announced its intention to sell while Forbes & Co. has advanced almost 16%.
Shock expulsion makes films porn movie this was the worst shit movie pube and poop
Since his shock expulsion, Cyrus has filed legal challenges to his dismissal from the board of Tata Sons and argued against Tata Sons turning into a private limited company — a move that has restricted the Mistry family’s ability to sell its stake freely.
Pallonji Mistry has a net worth of $21.4 billion, most of it due to his holding in the Tata Group, according to the Bloomberg Billionaires Index.
In a legal battle over the status of the Tata stake, India’s Supreme Court on Sept. 22 barred the Mistrys from pledging or selling any Tata shares until Oct. 28, after Tata told the court it can buy the Mistry family’s holdings if the latter needed funds.
Hours later, the SP Group signaled its intent to sell, calling the Tata move “vindictive” and saying it “believes that a separation of interests would best serve all stakeholder groups.”
The SP Group had 92.8 billion rupees in external debt at its main holding vehicle, Shapoorji Pallonji and Company Pvt., as of end-February, according to Care Ratings Ltd., while the group-wide debt was estimated to be more than 300 billion rupees as of March 2019. – Bloomberg
Disclosure: Tata Group’s chairman emeritus <NAME> is among the distinguished founder-investors of ThePrint. Please click here for details on investors."""

text1="What a shit movie pube"
print(check_list(text1))
print(check_list1(text1))<jupyter_output>True
Text contains 2 Swear Words.<jupyter_text>Q4 Using reduce functions: PTS:100  Add only even numbers in a list<jupyter_code>result = sum(filter(lambda x: x%2 ==0,range(20)))

print("Adding only Even number from the list : ", result)<jupyter_output>Adding only Even number from the list :  90<jupyter_text>Find the biggest character in a string (printable ascii characters)<jupyter_code>str = "find the biggest character in a string"
y=max(str)
res = [ord(y) for sub in y] 
print(f"Biggest Character in a string = {y} and ascii value for it = {res}")<jupyter_output>Biggest Character in a string = t and ascii value for it = [116]<jupyter_text>Adds every 3rd number in a list<jupyter_code>from functools import reduce
output = lambda n : reduce(lambda a,b: a+b, n[2::3])
print(output(range(12)))<jupyter_output>26<jupyter_text>Q5. Using randint, random.choice and list comprehensions, write an expression that generates 15 random KADDAADDDD number plates, where KA is fixed, D stands for a digit, and A stands for Capital alphabets. 10<<DD<<99 & 1000<<DDDD<<9999 PTS:100<jupyter_code>import string
import random

dd = list(range(10,100))
dddd = list(range(1000, 10000))
alphabet_list = list(string.ascii_uppercase)

def gen_KA_vehicle_num(n=15):
    results = []
    for i in range(n):
        cur_dd = random.choice(dd)
        cur_a1 = random.choice(alphabet_list)
        cur_a2 = random.choice(alphabet_list)
        cur_dddd = random.choice(dddd)
        results.append(f"KA{cur_dd}{cur_a1}{cur_a2}{cur_dddd}")
    return results

results = gen_KA_vehicle_num(n=15)

for vehicle_num in results:
    print(vehicle_num)<jupyter_output>KA39WP3215
KA18ZM4331
KA28UR2227
KA45QC3367
KA33SH1020
KA39ZY6864
KA35YD6084
KA58KN7824
KA73FN6319
KA28JZ2776
KA41MB3725
KA86XC9972
KA69NJ2259
KA73DH8025
KA74IJ1774<jupyter_text>Q6 Write the above again from scratch where KA can be changed to DL, and 1000/9999 ranges can be provided.  PTS:100<jupyter_code>import string
import random

dd = list(range(10,100))
dddd = list(range(1000, 10000))
alphabet_list = list(string.ascii_uppercase)

def gen_DL_vehicle_num(n=15):
    results = []
    for i in range(n):
        cur_dd = random.choice(dd)
        cur_a1 = random.choice(alphabet_list)
        cur_a2 = random.choice(alphabet_list)
        cur_dddd = random.choice(dddd)
        results.append(f"DL{cur_dd}{cur_a1}{cur_a2}{cur_dddd}")
    return results

results = gen_DL_vehicle_num(n=15)

for vehicle_num in results:
    print(vehicle_num)<jupyter_output>DL37KM2257
DL48WO9761
DL31GF6726
DL59HJ6674
DL16PA6100
DL55VB1490
DL67EN1637
DL29VU6321
DL98ZV3046
DL39OY7277
DL45EW5821
DL62WO9793
DL68QY2904
DL75AI7080
DL57JX6751
{'fraction_non_alphanumeric': 0.07277580071174378, 'fraction_numerical': 0.053202846975088966, 'mean_word_length': 4.897691500524659, 'pattern_counts': {'":': 0, '<': 47, '<?xml version=': 0, '>': 53, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 1, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 2, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '12', 'dir': 'jupyter-structured-clean-dedup', 'id': '350134', 'license': 'MIT', 'n_tokens_mistral': 3921, 'n_tokens_neox': 3428, 'n_words': 1529, 'path': 'ASG03/Assignment03.ipynb', 'repo_name': 'ishwarraja/END_NLP_P01', 'size': '11257'}