[Tutor] if value in list of dictionaries

Norman Khine norman at khine.net
Mon Sep 27 22:22:52 CEST 2010


hello, i have a list which is generated from a csv file:

options = [
	{'industry': 'travel', 'name': 'owner-director','value':
MSG(u"Owner/Director")},
	{'industry': 'travel', 'name': 'manager','value': MSG(u"Manager")},
	{'industry': 'travel', 'name': 'assistant-manager','value':
MSG(u"Assistant Manager")},
	{'industry': 'travel', 'name': 'travel-consultant','value':
MSG(u"Travel Consultant")},
	{'industry': 'travel', 'name': 'managing-director','value':
MSG(u"Managing Director")},
	{'industry': 'travel', 'name': 'sales-director','value': MSG(u"Sales
Director")},
	{'industry': 'travel', 'name': 'marketing-director','value':
MSG(u"Marketing Director")},
	{'industry': 'travel', 'name': 'marketing-manager','value':
MSG(u"Marketing Manager")},
	{'industry': 'travel', 'name': 'marketing-assistant','value':
MSG(u"Marketing Assistant")},
	{'industry': 'travel', 'name': 'product-manager','value':
MSG(u"Product Manager")},
	{'industry': 'travel', 'name': 'reservation-staff','value':
MSG(u"Reservation Staff")},
	{'industry': 'travel', 'name': 'student','value': MSG(u"Student")},
	{'industry': 'travel', 'name': 'other','value': MSG(u"Other")}]

what is the correct way to ensure that {'industry': 'travel', 'name':
'other','value': MSG(u"Other")} is always added to the end of this
list after all the items have been sorted?

here is the code which returns this list:

http://pastie.org/1185024

thanks

-- 
˙uʍop ǝpısdn p,uɹnʇ pןɹoʍ ǝɥʇ ǝǝs noʎ 'ʇuǝɯɐן sǝɯıʇ ǝɥʇ puɐ 'ʇuǝʇuoɔ
ǝq s,ʇǝן ʇǝʎ
%>>> "".join( [ {'*':'@','^':'.'}.get(c,None) or
chr(97+(ord(c)-83)%26) for c in ",adym,*)&uzq^zqf" ] )


More information about the Tutor mailing list