473,387 Members | 1,374 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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 1158
> #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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Hal Vaughan | last post by:
I'm working with javax.mail.*. I have no problem with reading in messages. I'm not using multi-part messages or anything, I just use this setup: Session oSession =...
5
by: Rob Somers | last post by:
Hey all I am writing a program to keep track of expenses and so on - it is not a school project, I am learning C as a hobby - At any rate, I am new to structs and reading and writing to files,...
51
by: Alan | last post by:
hi all, I want to define a constant length string, say 4 then in a function at some time, I want to set the string to a constant value, say a below is my code but it fails what is the correct...
3
by: JezB | last post by:
I know I can use the querystring mechanism to pass simple parameters to a Page using Response.Redirect, but Im having problems getting this to work using Server.Transfer or Server.Execute - is this...
3
by: Basil Fawlty | last post by:
Hi everyone, I could use some help in converting a simple Liberty BASIC program toa VB.NET 2003 SE program. I have built the simple form with a label, text box and button, Under the button I...
73
by: Claudio Grondi | last post by:
In the process of learning about some deeper details of Python I am curious if it is possible to write a 'prefix' code assigning to a and b something special, so, that Python gets trapped in an...
30
by: Brian Elmegaard | last post by:
Hi, I am struggling to understand how to really appreciate object orientation. I guess these are FAQ's but I have not been able to find the answers. Maybe my problem is that my style and...
8
by: rdrink | last post by:
I am just getting into pysqlite (with a fair amount of Python and MySQL experience behind me) and have coded a simple test case to try to get the hang of things... yet have run into a 'stock...
8
by: scottc | last post by:
i'm stuck and i need a little direction. i'm only getting 2 error messages. i have 2 files: import java.util.ArrayList; import java.util.*; //author public class StudentTester { ...
5
by: Kardon Coupé | last post by:
Dear All, I'm bemused, I'm moving an application I've written from VB6 into VS2005, and I'm getting all the fundamentals over before I delve into the hard part, like getting the forms layout...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.