<jupyter_start><jupyter_text>Bonus1: return an iterator (for example a generator) from your lstrip function instead of a list.<jupyter_code>def lstrip(iterable, obj):
    stop = False    
    for item in iterable:
        if stop:
            yield item
        elif item != obj:
            yield item
            stop = True          
   
x = lstrip([0, 1, 2, 3, 0], 0)
x
list(x)<jupyter_output><empty_output><jupyter_text>Bonus2: allow your lstrip function to accept a function as its second argument which will determine whether the item should be stripped<jupyter_code>def lstrip(iterable, obj):
    lstrip_stop = False    
    for item in iterable:
        if lstrip_stop:
            yield item
        else: 
            if not callable(obj):
                if item != obj:
                    yield item
                    lstrip_stop = True
            else:
                if not obj(item):
                    yield item
                    lstrip_stop = True
                    
def is_falsey(value): return not bool(value)
list(lstrip(['', 0, 1, 0, 2, 'h', ''], is_falsey))
list(lstrip([-4, -2, 2, 4, -6], lambda n: n < 0))
numbers = [0, 2, 4, 1, 3, 5, 6]
def is_even(n): return n % 2 == 0
list(lstrip(numbers, is_even))
list(lstrip([0, 0, 1, 0, 2, 3], 0))
list(lstrip('  hello ', ' '))<jupyter_output><empty_output><jupyter_text>Unit Tests<jupyter_code>import unittest

class LStripTests(unittest.TestCase):

    """Tests for lstrip."""

    def assertIterableEqual(self, iterable1, iterable2):
        self.assertEqual(list(iterable1), list(iterable2))

    def test_list(self):
        self.assertIterableEqual(lstrip([1, 1, 2, 3], 1), [2, 3])

    def test_nothing_to_strip(self):
        self.assertIterableEqual(lstrip([1, 2, 3], 0), [1, 2, 3])

    def test_string(self):
        self.assertIterableEqual(lstrip('  hello', ' '), 'hello')

    def test_empty_iterable(self):
        self.assertIterableEqual(lstrip([], 1), [])

    def test_strip_all(self):
        self.assertIterableEqual(lstrip([1, 1, 1], 1), [])

    def test_none_values(self):
        self.assertIterableEqual(lstrip([None, 1, 2, 3], 0), [None, 1, 2, 3])

    def test_iterator(self):
        squares = (n**2 for n in [0, 0, 1, 2, 3])
        self.assertIterableEqual(lstrip(squares, 0), [1, 4, 9])

    # To test the Bonus part of this exercise, comment out the following line
    # @unittest.expectedFailure
    def test_returns_iterator(self):
        stripped = lstrip((1, 2, 3), 1)
        self.assertEqual(iter(stripped), iter(stripped))

    # To test the Bonus part of this exercise, comment out the following line
    # @unittest.expectedFailure
    def test_function_given(self):
        numbers = [0, 2, 4, 1, 3, 5, 6]
        def is_even(n): return n % 2 == 0
        self.assertIterableEqual(lstrip(numbers, is_even), [1, 3, 5, 6])


if __name__ == "__main__":
    unittest.main(argv=['ignore-first-arg'], exit=False)<jupyter_output>.........
----------------------------------------------------------------------
Ran 9 tests in 0.004s

OK
{'fraction_non_alphanumeric': 0.15086913742210561, 'fraction_numerical': 0.03148573302722204, 'mean_word_length': 2.4385569334836528, 'pattern_counts': {'":': 1, '<': 13, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '431286', 'license': 'MIT', 'n_tokens_mistral': 1091, 'n_tokens_neox': 991, 'n_words': 287, 'path': 'Python/Python_Morsels_Revised/11.lstrip/let_me_try/lstrip.ipynb', 'repo_name': 'nitin-cherian/LifeLongLearning', 'size': '3049'}