1👍
✅
You could write a function like below adn get it
def get_choice(all_choices,search):
for choice in all_choices:
if choice[0] == search:
return choice[1]
return None
get_choice(all_choices,'JR')
- [Answered ]-Fastest way to find out whether row or one of set of rows exists in database accesed via SqlAlchemy
- [Answered ]-How to output a graph from Matplotlib in Django templates?
- [Answered ]-Cant find module Django while deploying on Elastic Beanstalk
- [Answered ]-Evaluate variable in context
- [Answered ]-IntegrityError -userprofile.u_id may not be NULL, django user registration
0👍
try this i think using using dictionary will be more efficient than list.the time complexity for dictionary is O(1) and for list it is O(n).
search = 'JR'
all_choices = Graduation.YEAR_IN_SCHOOL_CHOICES
dictionnary = {i[0]:i[1] for i in all_choices}
print(dictionnary[search])
- [Answered ]-Django RegexValidator does not display message
- [Answered ]-Django – Use postgres unaccent with django-filters library
- [Answered ]-How to save an in memory Excel file to a Django models.FileField
- [Answered ]-How to document Django URLs with Sphinx?
- [Answered ]-Django – Cannot display a form field as a textarea
Source:stackexchange.com