2 Replies - 200 Views - Last Post: 05 September 2013 - 07:19 PM Rate Topic: -----

#1 vasant_Gowda  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 27-August 13

searching for hexcode

Posted 05 September 2013 - 04:11 AM

Hi friends,

I have a onedictionary like

legendfile = [ 'Standard_Animator: blue, 3f7fff, 00bfff, 3fffbf, green, bfff3f, ffbf00, ff7f00, red' ,
'Standard_Animator_wrong: blu, 3f7fff, OObfff, 3fffbf, greeeen, bfff3f, ffbf00, ff7f00, red' ,
'Extended_Animator: LightGray, blue,3f7fff,00bfff,3fffbf,green,bfff3f,ffbf00,ff7f00,red, Magenta' ]

how can I check whether values of dictionary which is of type list (in above eg,blue,3fffff etc) is in hexcode

Is This A Good Question/Topic? 0
  • +

Replies To: searching for hexcode

#2 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3524
  • View blog
  • Posts: 12,033
  • Joined: 12-December 12

Re: searching for hexcode

Posted 05 September 2013 - 06:12 AM

That is not a dictionary (or a onedictionary?) but a list containing three strings.

You can either change your data structure or split() each string.

To test if a value is a valid hex-value you can use int() with a base (a radix) of 16:

print(int('3f7fff', 16))

This will either succeed or create a ValueError Exception.

This post has been edited by andrewsw: 05 September 2013 - 06:14 AM

Was This Post Helpful? 0
  • +
  • -

#3 woooee  Icon User is offline

  • D.I.C Head

Reputation: 21
  • View blog
  • Posts: 80
  • Joined: 21-November 12

Re: searching for hexcode

Posted 05 September 2013 - 07:19 PM

You can use the in operator to search a string but note that if 'bluegreen' is in the string it will return True for 'blue'. To test for multiples, i.e. 'blue' and '3fffbf' will require a list/table and you will have to test for both/all = True. Your string above appears to contain a combination of blue, green, and red triples, but is incomplete as the last value seems to be truncated.
legend =  'Standard_Animator: blue, 3f7fff, 00bfff, 3fffbf, green, bfff3f, ffbf00, ff7f00, red'
for lit in ['blue', 'orange', '3fffbf']:
    if lit in legend:
        print "True", lit
    else:
        print "False", lit 

This post has been edited by woooee: 05 September 2013 - 07:23 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1