Simple Problem: Getting rid of {}

Neal Holtz nholtz at docuweb.ca
Sat Mar 13 07:43:41 EST 2004


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 <dontbotherworld at yahoo.com> wrote in message news:<mailman.330.1079123993.19534.python-list at python.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_vector)
>         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



More information about the Python-list mailing list