Simple Problem: Getting rid of {}

Jeroen Wenting beefjerky at hornet.beefjerky.demon.nl
Sat Mar 13 05:19:22 EST 2004


> #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_vector)
>         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 :)





More information about the Python-list mailing list