You can use string.index()
to find the first character.
w= "AvaCdefh"
To change string to upper case
print w.upper() #Output: AVACDEFH
To change string to lower case
print w.lower() #Output: avacdefh
To find the first charchter using python built-in function:
print w.lower().index('a') #Output: 0
print w.index('a') #Output: 2
To reverse a word
print w[::-1] #Output: hfedCavA
But you can do this using comprehension list:
char='a'
# Finding a character in the word
findChar= [(c,index) for index,c in enumerate(list(w.lower())) if char==c ]
# Finding a character in the reversed word
inverseFindChar = [(c,index) for index,c in enumerate(list(w[::-1].lower())) if char==c ]
print findChar #Output: [('a', 0), ('a', 2)]
print inverseFindChar #Output: [('a', 5), ('a', 7)]
The other way to do it using lambda.
l = [index for index,c in enumerate(list(w.lower())) if char==c ]
ll= map(lambda x:w[x], l)
print ll #Output: ['A', 'a']
Then, you can wrap this as a function:
def findChar(char):
return " ".join([str(index) for index,c in enumerate(list(w.lower())) if char==c ])
def findCharInReversedWord(char):
return " ".join([str(index) for index,c in enumerate(list(w[::-1].lower())) if char==c ])
print findChar('a')
print findChar('c')
print findCharInReversedWord('a')