removing whitespace in concatenation of data during output

Hello,

I am re-factoring a script I have that used to use a dictionary but now is a list.  I need to be able to print the index value of positions in the list without any whitespace between them.  Here is a code snippet:

#!/usr/bin/env python

def getOhms (color1, color2, color3):
    """Version 2 of original getOhms using a list instead of a dictionary"""
    colors = ['black', 'brown', 'red', 'orange', 'yellow', 'green', 'blue',
              'violet', 'grey', 'white']
    print colors.index(color1), colors.index(color2), '0'*colors.index(color3)
   
getOhms('black', 'brown', 'red')

Run this way the output is:

0 1 00

I need it to be:

0100

Is there a way to remove this whitespace?

Thanks,
Brian
LVL 1
bnblazerAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

b0lsc0ttIT ManagerCommented:
bnblazer,

Try using the plus sign (+) instead of the comma.  The comma adds the space and you should be able to use the plus sign in its place in that spot in your code.

print colors.index(color1) + colors.index(color2)

b0lsc0tt
bnblazerAuthor Commented:
I tried that, but I get this error:

TypeError: unsupported operand type(s) for +: 'int' and 'str'


I think that it is grousing about the fact that the index of the list is an int and that the final portion of the statement produces a string.
bnblazerAuthor Commented:
Additionally, if I just replace the first comma with a +, it adds the values of the two index positions.
Become a Certified Penetration Testing Engineer

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

bnblazerAuthor Commented:
I found the answer I needed to do some string conversions:

print '%s' %colors.index(color1) + '%s' %colors.index(color2) + '0'*colors.index(color3)
b0lsc0ttIT ManagerCommented:
Sorry I wasn't quicker with the reply and answer.  Good job on the answer.  You can post a question in Community Support and have them PAQ the question, accept your answer, and refund the points.  Don't forget to include the URL to this question in that post.  You probably already know this but if you do have a question then let me know.
ramromconsultant Commented:
Even better: print '%s%s%s' % (colors.index(color1), colors.index(color2), '0'*colors.index(color3))

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
bnblazerAuthor Commented:
Ding!

I like that one ramrom.  How pythonic of you :)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Python

From novice to tech pro — start learning today.