View Single Post
Old 10-16-2011, 11:55 AM   #29
Noughty
Addict
Noughty is cognizant of many things which escape those who dream only by night.Noughty is cognizant of many things which escape those who dream only by night.Noughty is cognizant of many things which escape those who dream only by night.Noughty is cognizant of many things which escape those who dream only by night.Noughty is cognizant of many things which escape those who dream only by night.Noughty is cognizant of many things which escape those who dream only by night.Noughty is cognizant of many things which escape those who dream only by night.Noughty is cognizant of many things which escape those who dream only by night.Noughty is cognizant of many things which escape those who dream only by night.Noughty is cognizant of many things which escape those who dream only by night.Noughty is cognizant of many things which escape those who dream only by night.
 
Posts: 352
Karma: 103850
Join Date: Apr 2011
Device: Kindle NT
And I just wrote

Code:
return ', '.join(sorted(res))
Is it wrong? The result seems to be correct...

Where could I read more about functions in python?

Seems the speed increased by half a minute. Maybe I could make other columns like this too (genre, character). Since they are basically the same it might not be hard.

Code:
def evaluate(self, formatter, kwargs, mi, locals):
	# Tags is a multiple text field, so it is already split
	tags = set(mi.get('tags', []))
	# Shelf is a composite column, so we must split it
	shelf = set([l.strip() for l in mi.get('#shelf', "").split(',')])
	
	# items to remove from the result
	to_remove = set(['Short', 'delete', 'foo', 'bar', somethingElse',
		 'andSoOn', 'until I get tired', 'of adding things']) 

	# combine the two fields containing items we might want to keep.
	st = tags | shelf
	# now remove the items we don't want in the result
	res = st - to_remove
	return ', '.join(res)
I need another function. I need to leave the values I list, not remove them. For example I am doing the genre column, so I would list all genre values I have in my library, so in the returned list only they remain.

I need to extract specific values

Last edited by Noughty; 10-16-2011 at 12:05 PM.
Noughty is offline   Reply With Quote