Extract element from list containing single item in python

399
April 24, 2017, at 11:30 AM

I have a list containing only one element:

[u'\nUnited\napi\n\n0\n\n\n']

How can I extract only the digit 0?

Answer 1

Extract the same as you would from a string that is not in a list, except first you need to access the list item. Example:

mylist[0].strip().split()[-1]
Answer 2

You can use regular expression to extract that number

inp = [u'\nUnited\napi\n\n0\n\n\n']
re.search('(\d+)', inp[0).group(1)
READ ALSO
Set background color behind the image in matplotlib

Set background color behind the image in matplotlib

I'm trying to use Matplotlib in Python to display an image and show text at various points over itI'd like to make the image partially transparent, so to increase the visibility of the text

822
How can I visualize a color mapping?

How can I visualize a color mapping?

I have a function which takes a color in RGB format as input and outputs a color in RGB formatIt is guaranteed to be differentiable, but nothing else

357
Adding sparse matrix from CountVectorizer into dataframe with complimentary information for classifier - keep it in sparse format

Adding sparse matrix from CountVectorizer into dataframe with complimentary information for classifier - keep it in sparse format

I have the following problemRight now I am building a classifier system which will use text and some additional complimentary information as an input

505
Jupyter notebook can't show the regression summary

Jupyter notebook can't show the regression summary

I just met a problem when I did a regression analysis between two columns of data

293