python - Removing all alphabets and commas from a string -


I have a large list that contains many elements that look like this:

'A.21,48; B6 4, 91; C 9, 5, 125; D.139,166; E. 175,200 '

I want to strip all the letters and ; . Include the letters and the list that lists the ['21', '48', '64', '91', '95', '125', '139', '166', '175 ',' 200 ']

I tried to use it:

  import re list.append (re.sub ("\ D" / Code>  

But it results in a list like this - ['21 48 64] 95 125 139 166 175 200']

Since a lot The big file is working inside the loop, so a line of code will really be helpful.

Thanks

Text ">

You can re.findall () :

  & gt; & gt; import re & gt; & gt; Gt; Strs ('21', '48', '64', ' , Re.sub using '91', '95', '125', '139', '166', '175', '200]]   

() :

  gt;> ('21', '48', '64', '91', '95', '125', '13 9 ',' 166 ',' 175 ',' 200 ']   

Support (again. Fondal):

  Find the help module again: Findall (patterns, strings, flags = 0) return a list of all non-overlapping matches in the string. If one or more groups are present in the pattern, return a list of groups; This will be a list of tuples if more than one group of patterns is included in the blank match result    

Comments

Popular posts from this blog

excel vba - How to delete Solver(SOLVER.XLAM) code -

github - Teamcity & Git - PR merge builds - anyway to get HEAD commit hash? -

ios - Replace text in UITextView run slowly -