regex - Tokenizing blocks of code in Python -


I have this string:

  [a [ab] [cef] d]  

and I want this kind of list

  lst [0] = "a" lst [1] = "now" lst [2] = " CEF "My current implementation I do not think there are two recurring functions (one '[' and 'second division'] '') but I'm sure that this list can be done using the understanding or regular expressions. (But I have a sensible level to do this Can not understand).  

Any thoughts?

Actually this is not really a recursive data structure, note that a And d are in separate lists. You are dividing the string just by bracket characters and getting rid of some white space.

I'm sure someone can get some cleaner, but if you want to have a one-liner something like you would stop:

  parse_str = '[ A [ab] [cef] d] 'for lst = [s.strip () s.split (' [\ [\]] ', parse_str if s.strip ()]> gt; & Gt; Lst ['a', 'a b', 'ce f', 'd']  

Comments

Popular posts from this blog

c# - ListView onScroll event -

PHP - get image from byte array -

Linux Terminal Problem with Non-Canonical Terminal I/O app -