Click here to Skip to main content
13,087,566 members (93,360 online)
Rate this:
Please Sign up or sign in to vote.
See more:
Hallo Everybody,

I have been working on python, and I have got a problem. What is the way to make list of list of tuple, for example, [[(X, Y)]]. I am new on python.

Posted 1-May-13 4:18am

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Just like that: [[(X, Y)]]. Have you tried it?
Yonathan1111 1-May-13 10:57am
my intention was to Prepare a training Data for the HMM tagger, for a local corpus (ethiopic)

the tagger has the following syntax:

tagger = trainer.train_supervised(tr_data)

where the parameter tr_data should be in the format of List of List of Tuples

like, tr_data = [sent1, sent2,...]
where sent = [tuple1, tuple2],
and tuple = (word1, tag1), (word2, tag2),...

i have tried the following script, but all i get is just list of tuples, rather than list of list of tuples.

here is my script

import nltk;

wordtag = open("B:\Python\Teacher\Amharic_tagged_tr_corpus.txt","r");
wordtag = wordtag.readlines();
wordTagList = [];

for wt in wordtag:

sentlist = [];

for w in wordTagList:

tuple = [];
for s in sentlist:
for w in s:

tuplelist = [];
for t in tuple:
for w in t:

print tuplelis[0:3] will list list of tuples like, [(w,t),(w,t),...] , where what i need is [[(w,t), (w,t), ...],[],..]

any help?
lewax00 1-May-13 11:15am
I'm not familiar with "nltk", but assuming "str2tuple" returns a tuple, you're never creating the second level of the list, you're just appending to "tuplelist". So you'll only end up with a list of tuples. At some point you're going to need to create a new list, append that to tuplelist, then add tuples to that new list instead.
Yonathan1111 1-May-13 12:47pm
Thanks lewax00, I am going to try it. Thanks a lot

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web02 | 2.8.170813.1 | Last Updated 1 May 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100