<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def lookup_ids(handles):
 """ Fetch the twitter ids of each screen_name. """

    ids = set()
    for handle_list in [handles[100 * i:100 * i + 100] for i in range(len(handles))]:
        if len(handle_list) > 0:
            while True:
                r = twapi.request('users/lookup', {'screen_name': ','.join(handle_list)})
                if r.status_code in [88, 130, 420, 429]:  # rate limit
                    sys.stderr.write('Sleeping off rate limit for %s: %s\n' % (str(handle_list), r.text))
                    time.sleep(300)
                elif r.status_code == 200:
                    for item in r.get_iterator():
                        ids.add(item['id_str'])
                    break
                else:
                    sys.stderr.write('Error: %s\nSkipping %s...\n' % (str(handle_list), r.text))
                    break

    return ids