[Solved] obtaining substring from square bracket in a sentence


Here, I tried solving it. Here is my code :

bracket_string = '[apple]and[orange]and[apple]again!'

def find_tags(string1):
  start = False
  data=""
  data_list = []
  for i in string1:
    if i == '[':
      start = True
    if i != ']' and start == True:
      if i != '[':
        data += i
    else:
      if data != '':
        data_list.append(data)
      data=""
      start = False
  return(data_list)

x = find_tags(bracket_string)
print(x)

The function will return a list of items that were between brackets of a given string parameter.

Any advice will be appreciated.

3

solved obtaining substring from square bracket in a sentence