<commit_before># -*- coding: utf-8 -*-
""" IPython extension: add %clear magic """

import IPython.ipapi
ip = IPython.ipapi.get()

def clear_list(l):
    while l:
        l.pop()

def clear_f(self,arg):
    """ Clear various data (e.g. stored history data)
    
    %clear out - clear output history
    %clear in  - clear input history
    """
    
    api = self.getapi()
    for target in arg.split():
        if target == 'out':
            print "Flushing output cache (%d entries)" % len(api.user_ns()['_oh'])
            self.outputcache.flush()
        elif target == 'in':
            print "Flushing input history"
            from IPython import iplib
            clear_list(self.input_hist)
            clear_list(self.input_hist_raw)
            for n in range(1,self.outputcache.prompt_count + 1):
                key = '_i'+`n`
                try:
                    del self.user_ns[key]
                except: pass

ip.expose_magic("clear",clear_f)
    


<commit_msg>better way to clear a list<commit_after># -*- coding: utf-8 -*-
""" IPython extension: add %clear magic """

import IPython.ipapi
ip = IPython.ipapi.get()


def clear_f(self,arg):
    """ Clear various data (e.g. stored history data)
    
    %clear out - clear output history
    %clear in  - clear input history
    """
    
    api = self.getapi()
    for target in arg.split():
        if target == 'out':
            print "Flushing output cache (%d entries)" % len(api.user_ns()['_oh'])
            self.outputcache.flush()
        elif target == 'in':
            print "Flushing input history"
            from IPython import iplib
            del self.input_hist[:]
            del self.input_hist_raw[:]
            for n in range(1,self.outputcache.prompt_count + 1):
                key = '_i'+`n`
                try:
                    del self.user_ns[key]
                except: pass

ip.expose_magic("clear",clear_f)
    



{'fraction_non_alphanumeric': 0.12169860176074573, 'fraction_numerical': 0.0031071983428275505, 'mean_word_length': 1.8495575221238938, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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}}
{'dir': 'git-commits-cleaned', 'id': '3371722', 'n_tokens_mistral': 606, 'n_tokens_neox': 586, 'n_words': 160}