# Python3 Program To Swap First and Last Element of A List
# Python3 Program To Swap First and Last Element of A List
element of a list
def swapList(newList):
size = len(newList)
# Swapping
temp = newList[0]
newList[0] = newList[size - 1]
newList[size - 1] = temp
return newList
print(swapList(newList))
# Driver Code
if __name__ == "__main__":
def is_palindrome(s):
if len(s) < 1:
return True
else:
if s[0] == s[-1]:
return is_palindrome(s[1:-1])
else:
return False
a=str(input("Enter string:"))
if(is_palindrome(a)==True):
print("String is a palindrome!")
else:
print("String isn't a palindrome!")
if len(s) < 1:
return True
if s[0] == s[-1]:
return is_palindrome(s[1:-1])
else:
return False
result = is_palindrome(input_string)
if result:
print(f"{input_string} is a palindrome!")
else:
set1 = set(string1)
set2 = set(string2)
# Get the letters that are in both sets but not in their
intersection
if len(unique_letters) == 0:
else:
print(" ".join(sorted(unique_letters)))
5.) Write the problem to display all
permutations of a string in
lexicographic or dictionary order.
def print_permutations_lexicographic_order(s):
"""
"""
s = list(s)
s.sort()
# Loop over all permutations of the sorted list and print them
while True:
print("".join(s))
k = None
for i in range(len(s)-1):
k=i
if k is None:
break
# Find the largest index l greater than k such that s[k] < s[l]
l = None
l=i
s[k+1:] = s[k+1:][::-1]
# Get user input
print_permutations_lexicographic_order(s)
a = []
for i in range(n):
a.append(element)
for i in range(n-1):
for j in range(n-1-i):
if n < 2:
else:
def fibonacci(n):
"""
Compute the nth Fibonacci number.
"""
if n <= 1:
return n
else:
return fibonacci(n-1) + fibonacci(n-2)
"""
"""
return a[0]
pivot = a[0]
if i < len(left):
return select(left, i)
return mid[0]
else:
return select(right, i - len(left) - len(mid))
i = int(input("Enter i: "))
if n <= 1:
else:
if n % i == 0:
else:
uppercase_count = 0
lowercase_count = 0
if char.isupper():
uppercase_count += 1
elif char.islower():
lowercase_count += 1
return 0
if string[0] == char:
count1 = 0
count2 = 0
count1 += 1
count2 += 1
else:
letters_per_line = 5
alphabet = string.ascii_lowercase
letters = alphabet[i:i+letters_per_line]
file.write(letters + '\n')