|
| 1 | +raw = ['Artisan', 'live-edge', 'ugh', 'DIY', 'poutine', 'flexitarian', 'leggings', 'lo-fi', '3', 'wolf', 'moon', |
| 2 | + 'biodiesel', 'ennui', 'kombucha', 'gentrify', 'XOXO', 'health', 'goth.', 'Brunch', 'fixie', 'put', 'a', |
| 3 | + 'bird', 'on', 'it', 'you', 'probably', "haven't", 'heard', 'of', 'them', 'photo', 'booth', 'hell', 'of', |
| 4 | + 'bespoke', 'bicycle', 'rights.', 'Mustache', 'neutra', 'truffaut,', 'DIY', 'hoodie', 'slow-carb', 'pop-up', |
| 5 | + 'man', 'braid', 'pitchfork.', 'Artisan', 'activated', 'charcoal', 'tofu', 'shoreditch,', 'pug', 'readymade', |
| 6 | + 'church-key', '+1', 'iPhone', 'normcore', 'fingerstache', 'keytar', 'truffaut', 'lumbersexual', 'paleo.', |
| 7 | + 'Crucifix', 'austin', 'cred', 'taxidermy', 'truffaut', 'bicycle', 'rights', 'hell', 'of', 'pabst', |
| 8 | + 'activated', 'charcoal.', 'Narwhal', 'forage', 'letterpress', 'paleo', 'gentrify', 'la', 'croix', 'synth', |
| 9 | + 'freegan', 'bespoke', 'keytar.', 'Dreamcatcher', 'bespoke', 'bushwick', 'listicle', 'lomo.'] |
| 10 | + |
| 11 | +added_content = ['Kombucha', 'pop-up', 'blog', 'bitters', 'quinoa', 'blue', 'bottle', 'intelligentsia', 'flexitarian', |
| 12 | + 'copper', 'mug', 'pour-over', 'messenger', 'bag', "90's", 'neutra', 'lomo.', 'Hella', "90's", |
| 13 | + 'everyday', 'carry', 'mlkshk', 'scenester', 'four', 'dollar', 'toast', 'live-edge', 'cliche', 'wolf', |
| 14 | + 'truffaut', 'cronut', 'ramps', 'succulents.', 'Slow-carb', 'fam', 'blue', 'bottle', 'adaptogen', |
| 15 | + 'hammock', 'shoreditch.', 'Pour-over', 'fingerstache', 'mlkshk', 'tofu', 'normcore.', 'Tote', 'bag', |
| 16 | + 'four', 'dollar', 'toast', 'lumbersexual', 'raw', 'denim', 'venmo', 'kickstarter', 'fixie', |
| 17 | + 'stumptown', 'letterpress', 'locavore', 'echo', 'park', 'unicorn.', 'Forage', 'cardigan', 'tote', |
| 18 | + 'bag', 'mlkshk.', 'Unicorn', 'la', 'croix', 'kickstarter', 'coloring', 'book', 'ugh', 'tilde', |
| 19 | + 'sourdough', 'starter.'] |
| 20 | + |
| 21 | + |
| 22 | +""" |
| 23 | +Part 1: We have a list of content and we want to inject ads after the 3rd piece of content and then after every 4 |
| 24 | +pieces. |
| 25 | +
|
| 26 | +Part 2: We have 20 more pieces of content to add to the list and there should be ads between every 4 of them as a |
| 27 | +continuation of the previous list. |
| 28 | +""" |
| 29 | +def evenly_ad_ads(content_with_ads, content_without_ads, start_ad_index, ad_interval): |
| 30 | + # add one to make it so ads go after the interval instead of on the interval |
| 31 | + ad_interval = ad_interval + 1 |
| 32 | + |
| 33 | + content_length = len(content_without_ads) |
| 34 | + content_counter = 0 |
| 35 | + |
| 36 | + # iterate through the list and add either an AD or content until there is no more content to add |
| 37 | + while content_counter < content_length: |
| 38 | + content_with_ads_size = len(content_with_ads) |
| 39 | + if content_with_ads_size == start_ad_index or (content_with_ads_size - start_ad_index) % ad_interval == 0: |
| 40 | + content_with_ads.append("AD!") |
| 41 | + else: |
| 42 | + content_with_ads.append(content_without_ads[content_counter]) |
| 43 | + content_counter += 1 |
| 44 | + |
| 45 | + return content_with_ads |
| 46 | + |
| 47 | +""" |
| 48 | +what if we need to insert content into the middle of the list |
| 49 | +""" |
| 50 | +def insert_content(content_with_ads, inserted_content, insert_index, start_ad_index, ad_interval): |
| 51 | + # divide the list at the spot of insertion. Everything before the insertion spot should stay the same. |
| 52 | + content_with_ads_left = content_with_ads[:insert_index] |
| 53 | + content_with_ads_right = content_with_ads[insert_index:] |
| 54 | + # remove all of the ads after the insertion and re-add the ads after insertion |
| 55 | + content_without_ads_right = list(filter(lambda x: x != 'AD!', content_with_ads_right)) |
| 56 | + inserted_content.extend(content_without_ads_right) |
| 57 | + |
| 58 | + return evenly_ad_ads(content_with_ads_left, inserted_content, start_ad_index, ad_interval) |
| 59 | + |
| 60 | + |
| 61 | + |
| 62 | +parts_1_2 = evenly_ad_ads(evenly_ad_ads([], raw, 3, 4), added_content, 3, 4) |
| 63 | +inserted_list = insert_content(parts_1_2, ["INSERT1", "INSERT2", "INSERT3", "INSERT4"], 1, 3, 4) |
0 commit comments