Demo entry 4028849

Tokenize and search dictionary

   

Submitted by Tejaswi on Mar 14, 2016 at 01:05
Language: Python 3. Code size: 707 Bytes.

for p in productnames: 
	i = productnames.index(p)
	a = p.split()
	for element in a:
		indexOfElement = a.index(element)
		try:
			if a[indexOfElement-1] == 'for' or a[indexOfElement+1] == 'compatible':
				pass
			else:
				for item in dictionary:
					if item.lower() == element:
						brandnames[i].append(item)
					
		except IndexError:
			for item in dictionary:
				if item.lower() == element:
					brandnames[i].append(item)

	#If you didn't find any brandname maybe it's of size 2, hence take all possible combinations and compare

	for x, y in itertools.izip(a, a[1:]):
		x = x+" "+y
		for item in dictionary:
			if item.lower() == x.lower():
				brandnames[i].append(item)

This snippet took 0.00 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).