469,643 Members | 1,486 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,643 developers. It's quick & easy.

Simple Problem: Getting rid of {}

Hi,
I have done some string concatenation:

feature_vector={}
feature_element={}

#inside a loop

if (v==0):
feature_element=str(1)+"
"+str(index[i])+":"+str(vector[i])+" "
print feature_element
else:

feature_element=str(index[i])+":"+str(vector[i])+" "
feature_vector=str(feature_element)+str(feature_ve ctor)
if (v==0):
print feature_vector
when I print feature_vector I get my desired output
but with an extra {} in the end.

Output:

1 22389:0.0291806958474
1 22389:0.0291806958474 {}

I fail to understand why this is happening since
feature_element should also have {} in the end, if it
was the case with the variables I declared with like:
syntax{}

How to get rid of this extra {} from my string.

Thanks
Dont


__________________________________
Do you Yahoo!?
Yahoo! Search - Find what you’re looking for faster
http://search.yahoo.com

Jul 18 '05 #1
2 1057
> #inside a loop

if (v==0):
feature_element=str(1)+"
"+str(index[i])+":"+str(vector[i])+" "
print feature_element
else:
feature_element is a string here.
feature_element=str(index[i])+":"+str(vector[i])+" "
same here

feature_vector=str(feature_element)+str(feature_ve ctor)
if (v==0):
print feature_vector
here feature_vector is made a string you're doing feature_vector = "1
22389:0.0291806958474" + "{}" which yields the result you get.
when I print feature_vector I get my desired output
but with an extra {} in the end.

Output:

1 22389:0.0291806958474
1 22389:0.0291806958474 {}

I fail to understand why this is happening since
feature_element should also have {} in the end, if it
was the case with the variables I declared with like:
syntax{}

How to get rid of this extra {} from my string.

feature_vector.add(feature_element)
print " ".join("%s" %x for x in feature_vector)

or something along those lines :)
Jul 18 '05 #2
By starting it

feature_vector=''
feature_element=''

To see why, try this:

fv = {} # this creates an empty dictionary, not a string
print str(fv)
fv =''
print str(fv)

dont bother <do*************@yahoo.com> wrote in message news:<ma**************************************@pyt hon.org>...
Hi,
I have done some string concatenation:

feature_vector={}
feature_element={}

#inside a loop

if (v==0):
feature_element=str(1)+"
"+str(index[i])+":"+str(vector[i])+" "
print feature_element
else:

feature_element=str(index[i])+":"+str(vector[i])+" "
feature_vector=str(feature_element)+str(feature_ve ctor)
if (v==0):
print feature_vector
when I print feature_vector I get my desired output
but with an extra {} in the end.

Output:

1 22389:0.0291806958474
1 22389:0.0291806958474 {}

I fail to understand why this is happening since
feature_element should also have {} in the end, if it
was the case with the variables I declared with like:
syntax{}

How to get rid of this extra {} from my string.

Thanks
Dont


__________________________________
Do you Yahoo!?
Yahoo! Search - Find what you?re looking for faster
http://search.yahoo.com

Jul 18 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Rob Somers | last post: by
51 posts views Thread by Alan | last post: by
3 posts views Thread by JezB | last post: by
3 posts views Thread by Basil Fawlty | last post: by
73 posts views Thread by Claudio Grondi | last post: by
30 posts views Thread by Brian Elmegaard | last post: by
8 posts views Thread by rdrink | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.