Search code examples
pythonstringwords

How can I remove a double string to have it only be the first word?


I have a string that is the same word twice, i.e. "hihi". How can I remove the first 'hi' so only the second occurrence exists?


Solution

  • If the string is always double, you can split it in the middle.

    str_1 = "hihi"
    
    print(str_1[len(str_1)//2:])