Skip to content

Instantly share code, notes, and snippets.

View Pratik-Shukla-22's full-sized avatar

Pratik-Shukla-22

View GitHub Profile
#Python program to reverse an array:
def reverse_array(arr):
#Print the original array:
print(f"The original array is {arr}\n\n")
#Get the length of the array
n = len(arr)
#Python program to reverse an array with specific start and end values:
def reverse_array(arr,start,end):
#Print the original array:
print(f"The original array is {arr}\n\n")
#Get the length of the array
n = len(arr)
#Python program to find the length of an array
def find_len(arr):
#Initialize the counter with 0
count = 0
#Run a for loop to go through all the elements of the array
for element in arr:
#For each element in array increase the counter by 1
count = count + 1
#Python code for squirrels cigar party problem
def cigar_party(cigars, is_weekend):
#If it's a weekend
if(is_weekend):
#If number of cigars >=40
if(cigars>=40):
return True
#If it's not a weekend
#Python program for date_fashion
def date_fashion(you,date):
#If you or date is greater than or equal to 8
#And
#If you and your date's score is greater than 2
if((you>=8 or date >=8) and you>2 and date>2):
return 2
#If both scores are less than or equal to 2
#Import required libraries:
import numpy as np
import pandas as pd
#Creating a DataFrame:
data = {"Person":[["A","B","C"],[],"D",["E","F"]],
"House":[1,2,3,4],
"Money":[10,20,30,40]}
info = pd.DataFrame(data)
#Using the explode() function:
#Set ignore_index to False:
info.explode(column="Person", ignore_index=False)
#Using the explode() function:
#Set ignore_index to True:
info.explode(column="Person", ignore_index=True)
#Using the explode() function:
#ignore_index is False by Default:
info.explode(column="Person")
#Creating a pandas Series:
S = pd.Series([["A","B","C"],"D","E",["F","G"],[]])
S