def get_longest_string(lst):
longest_str = ''
for s in lst:
if len(longest_str) < len(s):
longest_str = s
return (longest_str, len(longest_str))
lst = ['Harish', 'Sandilya', 'Avadhanam']
get_longest_string(lst)
('Avadhanam', 9)
s = 'some string to use'
def remove_nth_char_from_string(string, index):
str1 = string[:index]
str2 = string[index+1:]
return str1+str2
remove_nth_char_from_string(s, 10)
'some strin to use'
s = 'some string to use'
def last_part_of_a_str_b4_specified_charecter(string, char):
index = s.rfind(char)
return string[:index]
last_part_of_a_str_b4_specified_charecter(s, 'u')
'some string to '
s = 'this is a sample string to demonstrate string lexicographical sorting'
def lex_sort(string):
words = string.split()
words.sort()
return words
lex_sort(s)
['a', 'demonstrate', 'is', 'lexicographical', 'sample', 'sorting', 'string', 'string', 'this', 'to']
s = 'This Is A Sample String Used To Pass To A Function To Remove Spaces'
def remove_spaces(string):
return s.replace(' ','')
remove_spaces(s)
'ThisIsASampleStringUsedToPassToAFunctionToRemoveSpaces'