-1

I'm just starting out with python. I'm trying to find the index of char present more than once

This is the sample string

08:28:57,990 DEBUG [http-0.0.0.0-18080-33] [tester] [1522412937602-580613] [TestManager] ABCD: loaded 35 test accounts

How should get the index of '[' and ']' present around 'TestManager' .

skhprabu
  • 73
  • 1
  • 2
  • 7

1 Answers1

0

This might help.

s = "08:28:57,990 DEBUG [http-0.0.0.0-18080-33] [tester] [1522412937602-580613] [TestManager] ABCD: loaded 35 test accounts"
for i in reversed(s.split()):    #Split string by space and reverse the list
    if ("[" in i) and ("]" in i):                 #Check if "[" and "]" in string
        print(i)
        break

Output:

[TestManager]
Rakesh
  • 81,458
  • 17
  • 76
  • 113