Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #107628

Re: Question on List processing

From Matt Wheeler <m@funkyhat.org>
Newsgroups comp.lang.python
Subject Re: Question on List processing
Date 2016-04-25 20:31 +0000
Message-ID <mailman.93.1461616308.32212.python-list@python.org> (permalink)
References <d0b4c737-3922-4b49-8f69-2564ba472950@googlegroups.com> <CAG93HwFn0SbR-CzrWk7U4eZ7sj7-RUwQxL_172jiZUWJZvZLjA@mail.gmail.com>

Show all headers | View raw


On Mon, 25 Apr 2016 15:56 , <subhabangalore@gmail.com> wrote:

> Dear Group,
>
> I have a list of tuples, as follows,
>
> list1=[u"('koteeswaram/BHPERSN engaged/NA himself/NA in/NA various/NA
> philanthropic/NA activities/NA  ','class1')", u"('koteeswaram/BHPERSN is/NA
> a/NA very/NA nice/NA person/NA  ','class1')", u"('koteeswaram/BHPERSN
> came/NA to/NA mumbai/LOC but/NA could/NA not/NA attend/NA the/ARTDEF
> board/NA meeting/NA  ','class1')", u"('the/ARTDEF people/NA of/NA
> the/ARTDEF company ABCOMP did/NA not/NA vote/NA for/NA koteeswaram/LOC
> ','class2')", u"('the/ARTDEF director AHT of/NA the/ARTDEF company,/NA
> koteeswaram/BHPERSN had/NA been/NA advised/NA to/NA take/NA rest/NA for/NA
> a/NA while/NA  ','class2')", u"('animesh/BHPERSN chauhan/BHPERSN arrived/NA
> by/NA his/PRNM3PAS private/NA aircraft/NA in/NA mumbai/LOC  ','class2')",
> u"('animesh/BHPERSN chauhan/BHPERSN met/NA the/ARTDEF prime/HPLPERST
> minister/AHT of/NA india/LOCC over/NA some/NA issues/NA  ','class2')",
> u"('animesh/BHPERSN chauhan/BHPERSN is/NA trying/NA to/NA set/NA up/NA a/NA
> plant/NA in/NA uk/LOCC  ','class3')", u"('animesh/BHPERSN chauh
>  an/BHPERSN is/NA trying/NA to/NA launch/NA a/NA new/ABCOMP office/AHT
> in/NA burdwan/LOC  ','class3')", u"('animesh/BHPERSN chauhan/BHPERSN is/NA
> trying/NA to/NA work/NA out/NA the/ARTDEF launch/NA of/NA a/NA new/ABCOMP
> product/NA in/NA india/LOCC  ','class3')"]
>

What you have is a list of strings, not tuples.

>
> I want to make it like,
>
> [('koteeswaram/BHPERSN engaged/NA himself/NA in/NA various/NA
> philanthropic/NA activities/NA','class1'),
>  ('koteeswaram/BHPERSN is/NA a/NA very/NA nice/NA person/NA  ','class1'),
> ('koteeswaram/BHPERSN came/NA to/NA mumbai/LOC but/NA could/NA not/NA
> attend/NA the/ARTDEF board/NA meeting/NA','class1'), ('the/ARTDEF people/NA
> of/NA the/ARTDEF company ABCOMP did/NA not/NA vote/NA for/NA
> koteeswaram/LOC  ','class2'),           ('the/ARTDEF director AHT of/NA
> the/ARTDEF company,/NA koteeswaram/BHPERSN had/NA been/NA advised/NA to/NA
> take/NA rest/NA for/NA a/NA while/NA  ','class2'), ('animesh/BHPERSN
> chauhan/BHPERSN arrived/NA by/NA his/PRNM3PAS private/NA aircraft/NA in/NA
> mumbai/LOC','class2'), ('animesh/BHPERSN chauhan/BHPERSN met/NA the/ARTDEF
> prime/HPLPERST minister/AHT of/NA india/LOCC over/NA some/NA
> issues/NA','class2'), ('animesh/BHPERSN chauhan/BHPERSN is/NA trying/NA
> to/NA set/NA up/NA a/NA plant/NA in/NA uk/LOCC','class3'),
> ('animesh/BHPERSN chauhan/BHPERSN is/NA trying/NA to/NA launch/NA a/NA
> new/ABCOMP office/AHT in/NA burdwan/LOC','class3'),
> ('animesh/BHPERSN chauhan/BHPERSN is/NA trying/NA to/NA work/NA out/NA
> the/ARTDEF launch/NA of/NA a/NA new/ABCOMP product/NA in/NA
> india/LOCC','class3')]
>
> I tried to make it as follows,
> list2=[]
> for i in train_sents:
>         a1=unicodedata.normalize('NFKD', i).encode('ascii','ignore')
>         a2=a1.replace('"',"")
>         list2.append(a2)


> and,
>
> for i in list1:
>         a3=i[1:-1]
>         list2.append(a3)
>

In both of these you seem to be trying to remove the double quote marks
from the strings, but they aren't part of the strings in the first place,
just delimiters.

>
>
> but not helping.
> If any one may kindly suggest how may I approach it?
>

Check out the documentation for ast.literal_eval

>

Back to comp.lang.python | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

Question on List processing subhabangalore@gmail.com - 2016-04-25 07:56 -0700
  Re: Question on List processing Steven D'Aprano <steve@pearwood.info> - 2016-04-26 02:36 +1000
    Re: Question on List processing subhabangalore@gmail.com - 2016-04-26 08:38 -0700
      Re: Question on List processing Random832 <random832@fastmail.com> - 2016-04-26 11:49 -0400
      Re: Question on List processing Steven D'Aprano <steve@pearwood.info> - 2016-04-27 02:29 +1000
    Re: Question on List processing subhabangalore@gmail.com - 2016-04-26 08:44 -0700
  Re: Question on List processing Matt Wheeler <m@funkyhat.org> - 2016-04-25 20:31 +0000

csiph-web