dictionary issue for formatted print

Dave Angel davea at davea.name
Sun Nov 9 14:41:41 CET 2014

Yusuf Can Bayrak <yusufcanbayrak at gmail.com> Wrote in message:
> when dictionary has one value for each key it's okey. I'm just type '% greek_letters' and it's working. 
> But how can i assign dict's values to formatted print, if it has more values than one. # -*- coding: utf-8 -*-greek_letters = {                    'omega': ['ω','Ω'], 'psi': ['ψ', 'Ψ'] , 'kapa': 'κ', 'to': ['τ', 'Τ'], 'lambda': ['λ', 'Λ'],                    'ksi': ['ξ', 'Ξ'], 'delta': ['δ', 'Δ'], 'mu': ['μ'], 'sigma': ['σ', 'Σ'], 'epsilon': ['ε', 'Ε'],                    'gamma': ['γ', 'Γ'], 'phi': ['φ', 'Φ'], 'theta': ['θ', 'Θ']                }print 'x(%(to)s) = A * cos(%(omega)s * %(to)s + %(theta)s)' % greek_letters.values()[1]

How do you intend for the logic to choose? You need to decide the
 logic  (usually by doing it by hand) before you can figure out
 how to code it.

My assumption is that you want the expression to decide  (the
 thing starting "A *"
). So you'll need to have two separate keys,
 like omega and Omega. The dictionary gets a little larger,  and
 it just works.


More information about the Python-list mailing list