Featured Post

How to Create a Symmetric Array in Python: A Fun Logic Exercise

Image
 Here's a Python program that says to write a Symmetric array transformation. A top interview question. Symmetric Array Transformation Problem: Write a Python function that transforms a given array into a symmetric array by mirroring it around its center. For example: Input: [1, 2, 3] Output: [1, 2, 3, 2, 1] Hints: Use slicing for the reverse part. Concatenate the original array with its mirrored part. Example def symmetric_array(arr):     """     Transforms the input array into a symmetric array by mirroring it around its center.     Parameters:     arr (list): The input array.     Returns:     list: The symmetric array.     """     # Mirror the array by concatenating the original with its reverse (excluding the last element to avoid duplication)     return arr + arr[-2::-1] # Example usage input_array = [1, 2, 3] symmetric_result = symmetric_array(input_array) print("Input Array:", input_arr...

The Perfect Way to Swap two Strings in Python

Here is the perfect way swap two strings in python. Without a third variable, you can swap strings in Python. With the swap function, you can achieve this. Here's the sample logic.


swap two strings in python

Swap two strings

Multiple arguments you can use in the same function. Here, a and b are arguments for the swap function. You'll get output as swapped when you use the swap function.


def swap(a, b): 
return b,a 


Logic to swap strings.

i = "Hello world"
j = "This is ApplyBigAnalytics" 

(i, j) = swap(i, j) 

print(i) 
print(j) 


Logic to Swap two numbers.

i = 1 
j = 2 

(i, j) = swap(i,j) 

print(i) 
print(j)


Here is output

This is ApplyBigAnalytics 
Hello world 

Comments

Popular posts from this blog

How to Fix datetime Import Error in Python Quickly

SQL Query: 3 Methods for Calculating Cumulative SUM

Big Data: Top Cloud Computing Interview Questions (1 of 4)