<commit_before>#!/usr/bin/env python
from __future__ import print_function
from __future__ import unicode_literals


class Graph(object):
    ''' Create an empty graph.
        Nodes must be hashable values.'''
    def __init__(self):
        self.graph = {}

    def nodes(self):
        ''' Return all the nodes in the graph. '''
        return self.graph.keys()

    def edges(self):
        ''' Return all teh edges in the graph as a list of tuples. '''
        return [(key, item) for key, value in self.graph.iteritems()
                for item in value]

    def add_node(self, node):
        ''' Add a node to the graph. '''
        self.graph.setdefault(node, [])

    def add_edge(self, node1, node2):
        ''' Add an edge to the graph. '''
        try:
            # Check if node1 is in the graph and add edge
            self.graph[node1].append(node2)
            # Check if node1 is in the graph
            if node2 not in self.graph:
                self.add_node(node2)
        except KeyError:
            # Add node1 to graph
            self.add_node(node1)
            # Add edge
            self.graph[node1].append(node2)
            # Check if node1 is in the graph
            if node2 not in self.graph:
                self.add_node(node2)

    def del_edge(self, node1, node2):
        ''' Delete an edge to the graph. '''
        try:
            # Check if node1 exists and node2 is a neighbor and delete the edge
            self.graph[node1].remove(node2)
        except KeyError:
            raise KeyError('node {} not in graph'.format(node1))
        except ValueError:
            raise ValueError('node {} not a neighbor'.format(node2))

    def del_node(self, node):
        ''' Delete a node from the graph. '''
        try:
            del self.graph[node]
            # Delete the node from any neighbor lists it is in.
            for value in self.graph.itervalues():<commit_msg>remove redundancy in add_edge function.<commit_after>#!/usr/bin/env python
from __future__ import print_function
from __future__ import unicode_literals


class Graph(object):
    ''' Create an empty graph.
        Nodes must be hashable values.'''
    def __init__(self):
        self.graph = {}

    def nodes(self):
        ''' Return all the nodes in the graph. '''
        return self.graph.keys()

    def edges(self):
        ''' Return all teh edges in the graph as a list of tuples. '''
        return [(key, item) for key, value in self.graph.iteritems()
                for item in value]

    def add_node(self, node):
        ''' Add a node to the graph. '''
        self.graph.setdefault(node, [])

    def add_edge(self, node1, node2):
        ''' Add an edge to the graph. '''
        # Add node1 to graph
        self.graph.setdefault(node1, [])
        # Add edge
        self.graph[node1].append(node2)
        # Check if node1 is in the graph
        if node2 not in self.graph:
            self.add_node(node2)

    def del_edge(self, node1, node2):
        ''' Delete an edge to the graph. '''
        try:
            # Check if node1 exists and node2 is a neighbor and delete the edge
            self.graph[node1].remove(node2)
        except KeyError:
            raise KeyError('node {} not in graph'.format(node1))
        except ValueError:
            raise ValueError('node {} not a neighbor'.format(node2))

    def del_node(self, node):
        ''' Delete a node from the graph. '''
        try:
            del self.graph[node]
            # Delete the node from any neighbor lists it is in.
            for value in self.graph.itervalues():
{'fraction_non_alphanumeric': 0.09938922820655191, 'fraction_numerical': 0.01110494169905608, 'mean_word_length': 1.9316517493897478, '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': '179666', 'n_tokens_mistral': 1023, 'n_tokens_neox': 998, 'n_words': 364}