python

how to get first character in string with skip initial letters


Can anyone help on this. Tried multiple I am new to this python. Need to get first character using python/pandas

Stack_over_flow

output should be : Sof

Appreciate your help on this. So that i can solve my issue. Can anyone help on this quick and efficient way?


Solution

  • Use split() to split the string at underscore characters. Then concatenate the first character of each word.

    string = 'Stack_over_flow'
    print(''.join(word[0] for word in string.split('_'))