Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Re: String to char and decimal number conversion

9 views
Skip to first unread message

Chris Rebert

unread,
Jan 10, 2011, 6:02:15 PM1/10/11
to SANKAR ., pytho...@python.org
On Mon, Jan 10, 2011 at 2:44 PM, SANKAR . <shank...@gmail.com> wrote:
> Hello There,
>
>        I am from non IT field also new to python programming.Could you
> please help me to solve the following problem?
>
> I have a list T1 with following format:
>
> T1 = [ ' "Field" ' , ' "12.5" ', ' "2.5" ']
>
> How do get the list elements without double quote in my output (T2).
>
> T2 =[ ' Field ' , ' 12.5 ', ' 2.5 ']

How are you obtaining T1 in the first place?

Cheers,
Chris
--
http://blog.rebertia.com

Alan Meyer

unread,
Jan 10, 2011, 10:50:55 PM1/10/11
to
On 1/10/2011 6:02 PM, Chris Rebert wrote:
> On Mon, Jan 10, 2011 at 2:44 PM, SANKAR .<shank...@gmail.com> wrote:
>> Hello There,
>>
>> I am from non IT field also new to python programming.Could you
>> please help me to solve the following problem?
>>
>> I have a list T1 with following format:
>>
>> T1 = [ ' "Field" ' , ' "12.5" ', ' "2.5" ']
>>
>> How do get the list elements without double quote in my output (T2).
>>
>> T2 =[ ' Field ' , ' 12.5 ', ' 2.5 ']

This will do it:
------------------------------------------------


T1 = [ ' "Field" ' , ' "12.5" ', ' "2.5" ']

T2 = []
for t in T1:
T2.append(t.replace('"', ''))
------------------------------------------------

The "replace" function acts on each element in T1, replacing every
double quote with nothing. We then append that to the new list T2.

Alan

Davish Bhardwaj

unread,
Jan 11, 2011, 5:41:50 AM1/11/11
to
On Jan 11, 4:02 am, Chris Rebert <c...@rebertia.com> wrote:


You can also do it like :


T1 = [ ' "Field" ' , ' "12.5" ', ' "2.5" ']

T2 = [t.replace('"', '') for t in T1]

This seems to me a more better and fast code ;)


Davish

Stefan Behnel

unread,
Jan 11, 2011, 8:08:07 AM1/11/11
to pytho...@python.org
SANKAR ., 11.01.2011 01:00:
> I am reading a Test.txt (see atatchment) file using following code to get
> the T2:
>
> F =open('C:\Test.txt','r')
> T1 = F.readlines()
> for i in range(len(T1)):
> T2 = T1[i].split(',')
> print(T2)

Take a look at the "csv" module in the standard library.

Stefan

0 new messages