Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #107628
| Path | csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail |
|---|---|
| From | Matt Wheeler <m@funkyhat.org> |
| Newsgroups | comp.lang.python |
| Subject | Re: Question on List processing |
| Date | Mon, 25 Apr 2016 20:31:28 +0000 |
| Lines | 79 |
| 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> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=UTF-8 |
| X-Trace | news.uni-berlin.de xRmUKV0ScTQ7DFXKMsJFLgYAgL7i75i9ALXJTrPwD5qw== |
| Return-Path | <m@funkyhat.org> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.024 |
| X-Spam-Evidence | '*H*': 0.95; '*S*': 0.00; 'skip:[ 20': 0.03; 'subject:Question': 0.05; 'suggest': 0.15; '2016': 0.16; 'helping.': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'to:name:python list': 0.16; 'wrote:': 0.16; 'skip:l 30': 0.18; 'email addr:gmail.com>': 0.18; "aren't": 0.22; 'trying': 0.22; 'tried': 0.24; 'header:In-Reply-To:1': 0.24; 'mon,': 0.24; 'message-id:@mail.gmail.com': 0.27; "skip:' 10": 0.28; 'skip:u 20': 0.28; 'skip:( 20': 0.28; 'strings,': 0.29; 'subject:List': 0.33; 'list': 0.34; 'received:google.com': 0.35; 'but': 0.36; 'skip:i 20': 0.36; 'received:209.85': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'seem': 0.37; 'received:209': 0.38; 'to:addr:python.org': 0.40; 'company': 0.60; 'group,': 0.60; 'skip:u 10': 0.61; 'director': 0.63; 'kindly': 0.64; 'skip:\xc2 10': 0.67; 'dear': 0.67; 'from:addr:m': 0.84 |
| X-Virus-Scanned | Debian amavisd-new at membrane.funkyhat.net |
| X-Gm-Message-State | AOPr4FW9n8Vyi886sdQWIoZTqYiroDgI/17ESLf0JRVNdkh52MXDpWofDBnz1Eut5WnNW+VRl8pRrV5sOyYpvQ== |
| X-Received | by 10.25.19.198 with SMTP id 67mr10642080lft.58.1461616299013; Mon, 25 Apr 2016 13:31:39 -0700 (PDT) |
| In-Reply-To | <d0b4c737-3922-4b49-8f69-2564ba472950@googlegroups.com> |
| X-Gmail-Original-Message-ID | <CAG93HwFn0SbR-CzrWk7U4eZ7sj7-RUwQxL_172jiZUWJZvZLjA@mail.gmail.com> |
| X-Content-Filtered-By | Mailman/MimeDel 2.1.22 |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.22 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| X-Mailman-Original-Message-ID | <CAG93HwFn0SbR-CzrWk7U4eZ7sj7-RUwQxL_172jiZUWJZvZLjA@mail.gmail.com> |
| X-Mailman-Original-References | <d0b4c737-3922-4b49-8f69-2564ba472950@googlegroups.com> |
| Xref | csiph.com comp.lang.python:107628 |
Show key headers only | 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 | Next — Previous in thread | Find similar | Unroll 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