0

I am trying to read an input which might have some information that I do not need for my program and for example I need only the part in brackets, how can I omit/eliminate that unneeded part? Just a simple example would be:

S={[2,5],[3,4],[5,6]}

So how can I omit everything and only take from the input [2,5] [3,4] and [5,6]?

Thank you!

bizzy
  • 1

2 Answers2

0

Suppose your string is that:

S="{[2,5],[3,4],[5,6]}"

print(S[S.find("{")+1:S.find("}")])

will return the substring inside the parenthesis '[2,5],[3,4],[5,6]'

Considering other options, I based my answer in the accepted one here

developer_hatch
  • 15,898
  • 3
  • 42
  • 75
0

assuming you data to be a string and similar to S={[2,5],[3,4],[5,6]} the noticeable thing is the { and } are in the position 0 and n-1 of the string ,n being the length of string you may use

 S={[2,5],[3,4],[5,6]}
print(S[1:-1])

where S[:] refer S[to begin with :to end ] as we want to omit data at pos 0 we begin with 1 and the last element '}' we use [1:-1] where -1 refers to last position similarly -2 will be second last and so on