Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

how to do swapping in python without sort function


# Python3 code to swap using XOR
 
x = 10
y = 5
 
# Code to swap 'x' and 'y'
x = x ^ y; # x now becomes 15 (1111)
y = x ^ y; # y becomes 10 (1010)
x = x ^ y; # x becomes 5 (0101)
 
print ("After Swapping: x = ", x, " y =", y)
Comment

how to do swapping in python without sort function

# Python3 program to
# swap two numbers
# without using
# temporary variable
x = 10
y = 5
 
# code to swap
# 'x' and 'y'
 
# x now becomes 50
x = x * y
 
# y becomes 10
y = x // y;
 
# x becomes 5
x = x // y;
 
print("After Swapping: x =",
              x, " y =", y);
Comment

how to do swapping in python without

def swap(xp, yp):
 
    xp[0] = xp[0] ^ yp[0]
    yp[0] = xp[0] ^ yp[0]
    xp[0] = xp[0] ^ yp[0]
 
 
# Driver code
x = [10]
swap(x, x)
print("After swap(&x, &x): x = ", x[0])
Comment

swapping in python

a = 10
b = 20
print("not swiped value of a is",a)
print("not swiped value of b is",b)
stored_value = a
a = b
b = stored_value
print("swiped value of a is",a)
print("swiped value of b is",b)

Comment

PREVIOUS NEXT
Code Example
Python :: django login code 
Python :: python save image to pdf 
Python :: Randint Random Library 
Python :: how to simplify fraction in python 
Python :: types of system 
Python :: add fonts to matplotlib from a particular location 
Python :: How to store password in hashlib in python 
Python :: python series to list of string 
Python :: python read file from same directory 
Python :: python multiaxis slicing 
Python :: clean nas from column pandas 
Python :: python url shortener 
Python :: flask subdomains 
Python :: find the index of a character in a string python 
Python :: numpy check if an array is all zero 
Python :: how to add two numbers 
Python :: calculate percentile pandas dataframe 
Python :: pyqt open file dialog 
Python :: plot a circle in python using equation of a circle 
Python :: python get list of file and time created 
Python :: python get attributes of object 
Python :: try catch python 
Python :: python keep value recursive function 
Python :: python argparse file argument 
Python :: pandas new column average of other columns 
Python :: fcm_django 
Python :: how to delete all instances of a model in django 
Python :: pygame.draw.rect() 
Python :: bitcoin wallet python 
Python :: notion python api 
ADD CONTENT
Topic
Content
Source link
Name
7+7 =