# Snippets

```import random as r
p = 'abcdefghijklmnopqrstuvwxyz0123456789%^*(-_=+)'           # Population
print(''.join(r.choices(p, k=10)))                       # Return a k sized list of population elements chosen with replacement.```
```def is_leap(year):

if year%4 == 0:

leap = True

if year % 100 == 0:

leap = True

if year % 400 ==0 :

leap = True

else:

leap = False

else:

leap = True

else:

leap = False

return leap

year = int(input())

print(is_leap(year))```
```# Function for nth fibonacci
# number - Space Optimisation
# Taking 1st two fibonacci numbers as 0 and 1

def fibonacci(n):
a = 0
b = 1

# Check is n is less
# than 0
if n < 0:
print("Incorrect input")

# Check is n is equal
# to 0
elif n == 0:
return 0

# Check if n is equal to 1
elif n == 1:
return b
else:
for i in range(1, n):
c = a + b
a = b
b = c
return b

# Driver Program
print(fibonacci(9))

# This code is contributed by Saket Modi
# Then corrected and improved by Himanshu Kanojiya
```
```# Function for nth fibonacci
# number - Dynamic Programming
# Taking 1st two fibonacci numbers as 0 and 1
FibArray = [0, 1]

def fibonacci(n):

# Check is n is less
# than 0
if n < 0:
print("Incorrect input")

# Check is n is less
# than len(FibArray)
elif n < len(FibArray):
return FibArray[n]
else:
FibArray.append(fibonacci(n - 1) + fibonacci(n - 2))
return FibArray[n]

# Driver Program
print(fibonacci(9))

# This code is contributed by Saket Modi
```
```# Function for nth Fibonacci number
def Fibonacci(n):

# Check if input is 0 then it will
# print incorrect input
if n < 0:
print("Incorrect input")

# Check if n is 0
# then it will return 0
elif n == 0:
return 0

# Check if n is 1,2
# it will return 1
elif n == 1 or n == 2:
return 1

else:
return Fibonacci(n-1) + Fibonacci(n-2)

# Driver Program
print(Fibonacci(9))

# This code is contributed by Saket Modi
# then corrected and improved by Himanshu Kanojiya
```
```def word_count(str):
counts = dict()
words = str.split()

for word in words:
if word in counts:
counts[word] += 1
else:
counts[word] = 1

counts_x = sorted(counts.items(), key=lambda kv: kv[1])
#print(counts_x)
return counts_x[-2]

print(word_count("Both of these issues are fixed by postponing the evaluation of annotations. Instead of compiling code which executes expressions in annotations at their definition time, the compiler stores the annotation in a string form equivalent to the AST of the expression in question. If needed, annotations can be resolved at runtime using typing.get_type_hints(). In the common case where this is not required, the annotations are cheaper to store (since short strings are interned by the interpreter) and make startup time faster."))

```
```from functools import reduce
fibSequence = lambda n: reduce(lambda x, _: x+[x[-1]+x[-2]], range(n-2), [0, 1])
print(fibSequence(10))
print(fibSequence(5))
print(fibSequence(6))```
```num1 = 5
num2 = 0
num3 = 12

factorial = lambda num : 1 if num <= 1 else num*factorial(num-1)

print("Factorial of", num1, ":", factorial(num1))
print("Factorial of", num2, ":", factorial(num2))
print("Factorial of", num3, ":", factorial(num3))```
`for i in range(1, 21): print("Fizz"*(i%3==0)+"Buzz"*(i%5==0) or str(i))`
```import IPython.display as ipd
ipd.Video("video.mp4", width=480)```