Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #80430

Re:dictionary issue for formatted print

From Dave Angel <davea@davea.name>
Subject Re:dictionary issue for formatted print
Date 2014-11-09 08:41 -0500
Organization news.gmane.org
References <CAEi_QX=X_pRmD1Zvy1Gqvo4+Wjj_fkqZSY5Vc06SggOzDmeJDQ@mail.gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.15598.1415540514.18130.python-list@python.org> (permalink)

Show all headers | View raw


Yusuf Can Bayrak <yusufcanbayrak@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.

-- 
DaveA

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re:dictionary issue for formatted print Dave Angel <davea@davea.name> - 2014-11-09 08:41 -0500

csiph-web