This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Using the explode() function: | |
#Set ignore_index to False: | |
info.explode(column="Person", ignore_index=False) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Using the explode() function: | |
#Set ignore_index to True: | |
info.explode(column="Person", ignore_index=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Using the explode() function: | |
#ignore_index is False by Default: | |
info.explode(column="Person") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Creating a pandas Series: | |
S = pd.Series([["A","B","C"],"D","E",["F","G"],[]]) | |
S |
OlderNewer