0% found this document useful (0 votes)
37 views5 pages

Left Shift Function (Lshift)

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
37 views5 pages

Left Shift Function (Lshift)

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

1.

Left Shift Function (LShift)

python

Copy code

def LShift(Arr, n):

return Arr[n:] + Arr[:n]

# Sample Input

Arr = [10, 20, 30, 40, 12, 11]

n=2

# Output

print(LShift(Arr, n)) # Output: [30, 40, 12, 11, 10, 20]

2. ReArrange Function

python

Copy code

def ReArrange(Arr):

half = len(Arr) // 2

return Arr[half:] + Arr[:half]

# Sample Input

Arr = [12, 5, 7, 23, 8, 10]

# Output

print(ReArrange(Arr)) # Output: [23, 8, 10, 12, 5, 7]

3. Swap Alternate Function (SwapAlternate)

python

Copy code

def SwapAlternate(Arr):

for i in range(0, len(Arr) - 1, 2):

Arr[i], Arr[i+1] = Arr[i+1], Arr[i]

return Arr

# Sample Input
Arr = [10, 20, 30, 40, 50, 60, 70]

# Output

print(SwapAlternate(Arr)) # Output: [20, 10, 40, 30, 60, 50, 70]

4. Puzzle Function

python

Copy code

def Puzzle(W, N):

return ''.join(['_' if (i + 1) % N == 0 else char for i, char in enumerate(W)])

# Sample Input

W = "TELEVISION"

N=3

# Output

print(Puzzle(W, N)) # Output: TEL_VIS_ON

5. Show Grades Function (showGrades)

python

Copy code

def showGrades(S):

for name, marks in S.items():

avg = sum(marks) / len(marks)

grade = 'A' if avg >= 90 else 'B' if avg >= 60 else 'C'

print(f"{name} - {grade}")

# Sample Input

S = {"Amit": [92, 86, 64], "Nagma": [65, 42, 43]}

# Output

showGrades(S) # Output: Amit - B, Nagma - C

6. Count Now Function (countNow)

python

Copy code

def countNow(Places):
return {k: v.upper() for k, v in Places.items() if len(v) > 5}

# Sample Input

Places = {1: "Delhi", 2: "London", 3: "New York"}

# Output

print(countNow(Places)) # Output: {2: 'LONDON', 3: 'NEW YORK'}

7. Length of Words Function (lenWords)

python

Copy code

def lenWords(STRING):

return tuple(len(word) for word in STRING.split())

# Sample Input

STRING = "come let us have some fun"

# Output

print(lenWords(STRING)) # Output: (4, 3, 2, 4, 4, 3)

8. XOXO Function

python

Copy code

def XOXO(L):

for i in range(len(L)):

for j in range(len(L[i])):

if L[i][j] == 'X':

L[i][j] = 'O'

elif L[i][j] == 'O':

L[i][j] = 'X'

return L

# Sample Input

L = [['X', 'X', 'O'], ['O', 'X', 'O'], ['O', 'O', 'X']]

# Output
print(XOXO(L)) # Output: [['O', 'O', 'X'], ['X', 'O', 'X'], ['X', 'X', 'O']]

9. No Two Three Function (NoTwoThree)

python

Copy code

def NoTwoThree(Arr):

for i, val in enumerate(Arr):

if val % 2 != 0 and val % 3 != 0:

print(f"{val} at location {i}")

# Sample Input

Arr = [25, 8, 12, 49, 9]

# Output

NoTwoThree(Arr) # Output: 25 at location 0, 49 at location 3

10. Add Odd Even Function (AddOddEven)

python

Copy code

def AddOddEven(VALUES):

even_sum = sum(x for x in VALUES if x % 2 == 0)

odd_sum = sum(x for x in VALUES if x % 2 != 0)

print(f"Even Sum: {even_sum}")

print(f"Odd Sum: {odd_sum}")

# Sample Input

VALUES = [15, 26, 37, 10, 22, 13]

# Output

AddOddEven(VALUES) # Output: Even Sum: 58, Odd Sum: 65

11. How Many Function (HowMany)

python

Copy code

def HowMany(ID, Val):

count = ID.count(Val)
print(f"{Val} found {count} Times")

# Sample Input

ID = [115, 122, 137, 110, 122, 113]

Val = 122

# Output

HowMany(ID, Val) # Output: 122 found 2 Times

12. ISTOUPCOUNT Function

python

Copy code

def ISTOUPCOUNT(S):

words = S.split()

count = sum(1 for word in words if word in ["IS", "TO", "UP"])

print(f"Count of IS TO and UP is {count}")

# Sample Input

S = "IT IS UP TO US TO TAKE CARE OF OUR SURROUNDING"

# Output

ISTOUPCOUNT(S) # Output: Count of IS TO and UP is 4

13. RetScholars Function (RetScholars)

python

Copy code

def RetScholars(D):

scholars = {k: v for k, v in D.items() if v >= 90}

return scholars

# Sample Input

D = {'Anu': 68, 'Raj': 75, 'jai': 92, 'Om': 93, 'Sam': 90}

# Output

print(RetScholars(D)) # Output: {'jai': 92, 'Om': 93, 'Sam': 90}

You might also like