Ho Jaye Padai
Ho Jaye Padai
Symmetrical or Palindrome
The objective is to determine whether or not the string is symmetrical and
palindrome. A string is said to be symmetrical if both halves of the string are the
same, and a string is said to be a palindrome if one half of the string is the opposite
of the other half or if the string appears the same whether read forward or backward.
My_string = input("Enter the string: ")
mid_value = int(len(My_string) / 2)
if len(My_string) % 2 == 0: # even
first_string = My_string[:mid_value]
second_string = My_string[mid_value:]
else: # odd
first_string = My_string[:mid_value]
second_string = My_string[mid_value+1:]
# condition to symmetric
if first_string == second_string:
print(My_string, 'Entered string is symmertical')
else:
print(My_string, 'Entered string is not symmertical')
#Using string replace() for removing the i'th character from a string
3. Removing the i’th character from a string using join() + list comprehension
method
My_string = "NaukriLearning"
My_string_len = len(My_string) # Storing the length of the string into a variable using string.length
function
new_string = '' #Creating an empty string that is used in the future to store the newly created string
print("first half of the given string in Uppercase and next half of string in Lowercase is: ",new_string)
# Driver's code
My_string = 'naukrilearning is best for learning python'
print("String before capitalizing the first and last character of each word in a string:", My_string)
print("String after capitalizing the first and last character of each word in a string:",
word_capping(My_string))
So, what exactly are we doing here? Firstly we are using a map function that returns
a map object (an iterator). The function within the map is then applied to each item of
the given iterable, which can be a list, tuple, string, or others. In our case a string.
The map function that we are applying to each element of the iterable
is My_string[:-1]+My_string[-1].upper() which converts the last letter off each
substring to uppercase. The elements that we are passing are a list of substrings
with their first letter capital and the rest of them in lowercase. This is achieved by
title() and split() function. The split function separates the string into a list of
substrings. Lastly, these modified items are put together to form a string using the
join() function.
Write a Python Program to Count the Number of
Digits, Alphabets, and Other Characters in a String
Here we are using isalpha() and isdigit() function and a for loop with if_else
statements to count the number of digits, alphabets, and other special characters.
My_string = "Naukrilearning@123"
alphabets = 0
digits = 0
special_char =0
# To Count Alphabets, Digits and Special Characters in a String using For Loop, isalpha() and isdigit()
function
for i in range(len(My_string)):
if(My_string[i].isalpha()):
alphabets = alphabets + 1
elif(My_string[i].isdigit()):
digits = digits + 1
else:
special_char = special_char + 1
print(check_String (str('naukrilearning')))
print(check_String (str('1naukrilearning1')))
# Driver Code
# string object
My_string = 'NaukriLearning'
print ("The maximum of all characters in Naukrilearning is best for learning python is : " + str(flag))
Ok! That looks complex, ain’t it? Well, it really isn’t. Here, we are using Python
Counter, which is a container that allows you to count the items in an iterable object,
here string. It returns a dictionary object where elements and the count are
represented as key-value pairs. Now that you have the count of each character, all
you need is to find the one with the maximum count using the max function.
print ("Count of all characters in Naukrilearning is best for learning python is :\n " , str(flag1))
print ("Count of all characters in Naukrilearning is best for learning python is :\n " , str(flag2))
print ("Count of all characters in Naukrilearning is best for learning python is :\n " , str(flag3))
done= False
iteration = 0
rand_stringNext = ''
done = True
# increase iteration
iteration += 1
rand_string1 = rand_stringNext
time.sleep(0.1)
res_Str = ""
for index in range(len(string)):
if index != i:
res_Str = res_Str + string[index]
return substring_list
def join_the_string(substring_list):
return string1
# Driver Code
if __name__ == '__main__':
test_string1 = 'Python is the best'
# Splitting a string
substring_list = split_the_string(test_string1)
print(substring_list)
def allPermuationsPossible(string):
#Driver code
if __name__ == "__main__":
string = input('Enter the string : ')
allPermuationsPossible(string)
# Driver Code
org_string = 'https://www.shiksha.com/online-courses/ you will get to read awsome blog at link /
https://www.shiksha.com/online-courses/articles/'
print("Url is :: ", check_for_urls(org_string))