Find an element in a list… here is a solution to the problem.
Find an element in a list
I
have a file where I want to find elements.
import unittest
import json
import requests
class Test(unittest. TestCase):
def test_description(self):
api_url = 'https://api.myjson.com/bins/mtthu'
r = requests.get(api_url))
if __name__ == '__main__':
unittest.main()
Solution
Add another line to test_description and use the in
keyword:
self.assertTrue(any('young' in c['Description'] for c in charities))
See:
print(('young' in 'abc', 'young' in 'abc young'))