Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: String to char and decimal number conversion

Reply
Thread Tools

Re: String to char and decimal number conversion

 
 
Chris Rebert
Guest
Posts: n/a
 
      01-10-2011
On Mon, Jan 10, 2011 at 2:44 PM, SANKAR . <(E-Mail Removed)> 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
 
Reply With Quote
 
 
 
 
Alan Meyer
Guest
Posts: n/a
 
      01-11-2011
On 1/10/2011 6:02 PM, Chris Rebert wrote:
> On Mon, Jan 10, 2011 at 2:44 PM, SANKAR .<(E-Mail Removed)> 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
 
Reply With Quote
 
 
 
 
Davish Bhardwaj
Guest
Posts: n/a
 
      01-11-2011
On Jan 11, 4:02*am, Chris Rebert <(E-Mail Removed)> wrote:
> On Mon, Jan 10, 2011 at 2:44 PM, SANKAR . <(E-Mail Removed)> 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



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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Conversion from Hexadecimal number into Decimal number dharmdeep@gmail.com C Programming 14 11-16-2006 07:51 PM
Decimal to Packed Decimal Conversion in C++ Ven C++ 3 08-01-2006 03:56 PM
(const char *cp) and (char *p) are consistent type, (const char **cpp) and (char **pp) are not consistent lovecreatesbeauty C Programming 1 05-09-2006 08:01 AM
/usr/bin/ld: ../../dist/lib/libjsdombase_s.a(BlockGrouper.o)(.text+0x98): unresolvable relocation against symbol `std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostre silverburgh.meryl@gmail.com C++ 3 03-09-2006 12:14 AM
Hexadecimal To Decimal Conversion (Via Char Array) A_StClaire_@hotmail.com C++ 2 08-13-2005 01:44 AM



Advertisments