comparison between the items of one list with the items of another list both of which reside in an outer list
working with a big list This is my earlier post about this program which generates the following list. The program I am writing deals with a big linked list. This list is called phonemeList. The list is like the following:
[[('dh', [[-1, -1], [-1, -1], [-1, -1], [-1, -1], [0.15, 0.35], [-1, -1]]),
('ih', [[-1, -1], [-1, -1], [0.3, 1.0], [-1, -1], [0.05, 0.15], [-1,-1]]),
("'", None),
('k', [[-1, -1], [-1, -1], [-1, -1], [-1, -1], [0.15, 0.8], [-1, -1]]),
('aa', [[-1, -1], [-1, -1], [-1, -1], [-1, -1], [0.15, 1.0], [-1, -1]]),
('r', [[-1, -1], [-1, -1], [-1, -1], [-1, -1], [0.15, 0.6], [-1, -1]]),
("'", None),
('p', [[-1, -1], [0.2, 1.0], [-1, -1], [-1, -1], [0.15, 0.2], [-1, -1]]),
('ih', [[-1, -1], [-1, -1], [0.3, 1.0], [-1, -1], [0.05, 0.15], [-1, -1]]),
("'", None),
('k', [[-1, -1], [-1, -1], [-1, -1], [-1, -1], [0.15, 0.8], [-1, -1]]),
('iy', [[-1, -1], [-1, -1], [0.3, 1.0], [-1, -1], [0.1, 0.15], [-1, -1]]),
('ng', [[-1, -1], [-1, -1], [0.3, 1.0], [-1, -1], [0.09, 0.3], [-1, -1]]),
("'", None),
('er', [[-1, -1], [-1, -1], [-1, -1], [-1, -1], [0.15, 0.5], [-1, -1]]),
("'", None),
('sh', [[-1, -1], [-1, -1], [-1, -1], [0.3, 1.0], [-1, -1], [-1, -1]]),
('eh', [[-1, -1], [-1, -1], [0.1, 0.5], [-1, -1], [0.4, 0.7], [-1, -1]]),
('m', [[-1, -1], [0.2, 1.0], [-1, -1], [-1, -1], [0.15, 0.2], [-1, -1]]),
("'", None),
('p', [[-1, -1], [0.2, 1.0], [-1, -1], [-1, -1], [0.15, 0.2], [-1, -1]]),
('uw', [[-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [0.5, 1.0]]),
('dx', [[-1, -1], [-1, -1], [-1, -1], [-1, -1], [0.15, 0.35], [-1, -1]]),
("'", None),
('aa', [[-1, -1], [-1, -1], [-1, -1], [-1, -1], [0.15, 1.0], [-1, -1]]),
("'", None),
('er', [[-1, -1], [-1, -1], [-1, -1], [-1, -1], [0.15, 0.5], [-1, -1]]),
("'", None), ('aa', [[-1, -1], [-1, -1], [-1, -1], [-1, -1], [0.15, 1.0], [-1,-1]]),
("'", None),
('r', [[-1, -1], [-1, -1], [-1, -1], [-1, -1], [0.15, 0.6], [-1, -1]]),
('iy', [[-1, -1], [-1, -1], [0.3, 1.0], [-1, -1], [0.1, 0.15], [-1, -1]]),
("'", None),
('ih', [[-1, -1], [-1, -1], [0.3, 1.0], [-1, -1], [0.05, 0.15], [-1, -1]]),
('n', [[-1, -1], [-1, -1], [-1, -1], [0.3, 1.0], [-1, -1], [-1, -1]]),
('t', [[-1, -1], [-1, -1], [-1, -1], [-1, -1], [0.15, 0.4], [-1, -1]]),
('l', [[-1, -1], [-1, -1], [-1, -1], [-1, -1], [0.15, 0.6], [-1, -1]]),
("'", None), ('r', [[-1, -1], [-1, -1], [-1, -1], [-1, -1], [0.15,0.6], [-1, -1]]),
('ah', [[-1, -1], [-1, -1], [-1, -1], [-1, -1], [0.15, 1.0], [-1, -1]]),
('k', [[-1, -1], [-1, -1], [-1, -1], [-1, -1], [0.15, 0.8], [-1, -1]])]]
Could you kindly have a look at the link so that you have an idea about the program. Thank you. [0.15,0.6] is not a list but a range. Here it is expressed as a list which may be wrong. This means the value can vary from 0.15 to 0.6. Where as [-1,-1] is a no range thing which is not in use and can be replaced by a range of positive numbers while comparing. Now I need to compare the items of 'dh' with the items of 'ih' . The first item of 'dh' will be compared to first item of 'ih' then 2nd item to 2nd and so on. Then the items of 'dh' will be compared to items of 'k' ignoring "'". 'dh' will be compared to all following the rules. Then 'ih' comes into picture and the s开发者_如何学JAVAame thing is repeated. While doing this ("'", None), should be ignored. The ranges get changed during comparison and [-1,-1] will be replaced. The ("'", None) is like a boundary. After comparison of all items with one another, the next step would be to compare within these boundaries. Being a beginner this is really a complex thing for me. But this is also my main project so please help me with this. Thank you very much.
Honestly, sounds like you need a class, not a nested list.
class Phoneme():
def __init__(self,named,variables,for,every,paired,value,in,the,crazy,list,you,posted):
self.named = named
self.variables = variables
##etc
##This way, we can see what you're comparing. The comparisons also become much easier.
Now your compares can literally just be something like:
if phoneme1.fricative == phoneme2.fricative:
do_something_awesome()
Ah, if classes are confusing, I'd suggest you check out these links. Those 4 tutorials are fairly decent descriptions of classes. The last one is the official tutorial, start with that one. Dive into Python is another excellent example, but it's geared towards those who already know another programming language, so if Python is your first, it might be a bit daunting.
精彩评论