Search code examples
pythoncurrency

How to deduce/print the currency code from the currency symbol using Python?


I have certain documents from which i have extracted the currency symbol like €, £, $ etc.

I want to write a code in python where after reading these symbols it can give me the respective currency code as an output.

For eg. if i get the currency symbol as , the output should be EURO or if the currency symbol is $ the output should be USD


Solution

  • Use a Dictionary. These are like Hash Tables.

    currency = { "€": "EURO", "$": "USD" }
    print (currency["$"])
    

    Prints USD