string bug/oddity?
William Park
opengeometry at yahoo.ca
Sun Aug 12 19:59:30 EDT 2001
On Sun, Aug 12, 2001 at 07:45:15PM -0400, Peter Hansen wrote:
> Oktay Safak wrote:
> >
> > First I constructed a dictionary a. Here it is:
> >
> > {'yas': 23, 'ad': 'veli', 'soyad': 'guzel'}
> > >>> for x in a.keys():
> > if type(a[x])!="string": print x+repr(a[x])
> > else: print x+a[x]
> >
> >
> > yas23
> > ad'veli'
> > soyad'guzel'
> >
> > I just want to concatenate the two strings without the
> > quotes as in the last line.
>
> Anything wrong with this, simpler, approach?
>
> >>> for x in a.keys():
> ... print '%s%s' % (x, a[x])
This is better solution. But, for educational purpose, in the original
code, 'type()' returns special type values, not a regular string. So,
what your want is
type(a[x]) != type("")
--
William Park, Open Geometry Consulting, <opengeometry at yahoo.ca>
8 CPUs cluster, (Slackware) Linux, Python, LaTeX, Vim, Mutt, Sc.
More information about the Python-list
mailing list