python - Most pythonic way to check if a 1-dimensional list is an element of a 2-dimensional list? -



python - Most pythonic way to check if a 1-dimensional list is an element of a 2-dimensional list? -

using python 2.7.6, have list of rgb colors, each list, ie.:

color_list = [ [0, 0, 0], [255, 0, 0]....[255, 255, 255] ]

calling this:

color = [0, 0, 0] if color in color_list: # stuff

elicits:

valueerror: truth value of array more 1 element ambiguous. utilize a.any() or a.all()

i'm concerned doing error suggests, ie. color.any() or color.all() literally going go looking integers anywhere in color list. can think ways accomplish actual aims, intuition python has well-seen need coming , there's pythonic way accomplish it. lil' help?

update

i'm fail. color in above code numpy.ndarray

the error message you're seeing coming numpy.

this means either color numpy array, or color_list is, or color_list list of numpy arrays. if lists, code have worked.

color_list = [ [0, 0, 0], [255, 0, 0], [255, 255, 255] ] color = [0, 0, 0] color in color_list => true

python python-2.7

Comments

Popular posts from this blog

php - How to pass multiple values from url -

xslt - DocBook 5 to PDF transform failing with error: "fo:flow" is missing child elements. Required content model: marker* -

database - php search bar when I press submit with nothing in the search bar it shows all the data -