3python Live Class Upload-1
3python Live Class Upload-1
Examples:
Input : [1, 2, 3]
Output : [3, 2, 1]
Solution 1 : Python program to interchange first
and last elements in a list
# Python3 program to swap first
# and last element of a list
# Swap function
def swapList(newList):
size = len(newList)
# Swapping
temp = newList[0]
newList[0] = newList[size - 1]
newList[size - 1] = temp
return newList
# Driver code
newList = [12, 35, 9, 56, 24]
print(swapList(newList))
Solution 2 : Python program to interchange first
and last elements in a list
# Python3 program to swap first
# and last element of a list
# Swap function
def swapList(newList):
return newList
# Driver code
newList = [12, 35, 9, 56, 24]
print(swapList(newList))
Solution 3 : Python program to interchange first
and last elements in a list
# Python3 program to swap first
# and last element of a list
# Swap function
def swapList(list):
return list
# Driver code
newList = [12, 35, 9, 56, 24]
print(swapList(newList))
Solution 4 : Python program to interchange first
and last elements in a list
# Python3 program to swap first
# and last element of a list
# Swap function
def swapList(list):
first = list.pop(0)
last = list.pop(-1)
list.insert(0, last)
list.append(first)
return list
# Driver code
newList = [12, 35, 9, 56, 24]
print(swapList(newList))
Problem : Python program to check if a string is
palindrome or not
Examples:
Input : malayalam
Output : Yes
Input : geeks
Output : No
Solution 1 : Python program to check if a string is
palindrome or not
# function which return reverse of a string
def isPalindrome(s):
return s == s[::-1]
# Driver code
s = "malayalam"
ans = isPalindrome(s)
if ans:
print("Yes")
else:
print("No")
Solution 2 : Python program to check if a string is
palindrome or not
# function to check string is
# palindrome or not
def isPalindrome(str):
# main function
s = "malayalam"
ans = isPalindrome(s)
if (ans):
print("Yes")
else:
print("No")
Solution 3 : Python program to check if a string is
palindrome or not
# function to check string is
# palindrome or not
def isPalindrome(s):
# main function
s = "malayalam"
ans = isPalindrome(s)
Problem : Python program to create a list of tuples from
given list having number and its cube in each tuple
Example:
# creating a list
list1 = [1, 2, 5, 6]
Examples:
*****
****
***
**
*
Solution : Python | Print an Inverted Star Pattern
# python 3 code to print inverted star
# pattern
# i is going to be enabled to
# range between n-i t 0 with a
# decrement of 1 with each iteration.
# and in print function, for each
iteration,
# ” ” is multiplied with n-i and ‘*’ is
# multiplied with i to create correct
# space before of the stars.
for i in range (n, 0, -1):
print((n-i) * ' ' + i * '*')
Slack Invite Link
https://join.slack.com/t/perfect-plan-b/sh
ared_invite/zt-drplefyv-x1vurrlFy98UOe1
irCfLXw
Social Media Links
Facebook: https://www.facebook.com/IshanPlanB/
Twitter: https://twitter.com/PerfectPlanB1
Linkedin: https://www.linkedin.com/company/perfect-plan-b/
Instagram: https://www.instagram.com/perfect_plan_b/
Quora:
https://www.quora.com/q/hreieuophqgaswqv?ch=10&share=41d2481e&srid=E
R3y0
Youtube: https://www.youtube.com/channel/UCQJFQlCdcq4XxJDqE3IqmbQ