<s> import json <EOL> import requests <EOL> pop_json_url = "<STR_LIT>" <EOL> pop_list = requests . get ( pop_json_url ) . json ( ) <EOL> pop_list <EOL> total = <NUM_LIT:0> <EOL> for country in pop_list : <EOL> total += country [ <NUM_LIT:2> ] <EOL> print total <EOL> sum ( [ country [ <NUM_LIT:2> ] for country in pop_list ] ) <EOL> sum ( [ country [ <NUM_LIT:2> ] for country in pop_list if country [ <NUM_LIT:0> ] is not None ] ) <EOL> import json <EOL> import requests <EOL> cia_json_url = "<STR_LIT>" <EOL> cia_list = requests . get ( cia_json_url ) . json ( ) <EOL> cia_world_pop = sum ( [ r [ <NUM_LIT:2> ] for r in cia_list if r [ <NUM_LIT:1> ] != '<STR_LIT>' ] ) <EOL> cia_world_pop <EOL> import bisect <EOL> import random <EOL> from itertools import repeat , islice <EOL> from collections import Counter <EOL> def cumsum ( lis ) : <EOL> total = <NUM_LIT:0> <EOL> for x in lis : <EOL> total += x <EOL> yield total <EOL> world_pop = sum ( [ r [ <NUM_LIT:2> ] for r in pop_list ] ) <EOL> cum_pop = list ( cumsum ( ( r [ <NUM_LIT:2> ] for r in pop_list ) ) ) <EOL> def random_country_weighted_by_pop ( ) : <EOL> while True : <EOL> yield pop_list [ bisect . bisect_left ( cum_pop , random . randint ( <NUM_LIT:1> , world_pop ) ) ] [ <NUM_LIT:1> ] <EOL> Counter ( islice ( random_country_weighted_by_pop ( ) , <NUM_LIT:5> ) ) </s>
