title: Accessing List from outside function
body: <p>I have a list that I create inside of <code>function1</code>. I want to be able to access and modify it in <code>function2</code>. How can I do this without a global variable? </p>
  
  <p>Neither function is nested within the other and I need to be able to generalize this for multiple lists in several functions. </p>
  
  <p>I want to be able to access <code>word_list</code> and <code>sentence_starter</code> in other functions.</p>
  
  <pre><code>def Markov_begin(text):
      print create_word_lists(text)
      print pick_starting_point(word_list)
      return starting_list
  
  
  def create_word_lists(filename):
     prefix_dict = {}    
     word_list = []
     sub_list = []
     word = ''
  
     fin = open(filename)
     for line in fin:
        the_line = line.strip()
        for i in line:
             if i not in punctuation:
                 word+=(i)
             if i in punctuation:
                 sub_list.append(word)
                 word_list.append(sub_list)
                 sub_list = []
                 word = ''
        sub_list.append(word)
        word_list.append(sub_list)
     print 1
     return word_list
  
  def pick_starting_point(word_list):
      sentence_starter = ['.','!','?']
      starting_list = []
      n = 0
      for n in range(len(word_list)-1):
          for i in word_list[n]:
              for a in i:
                  if a in sentence_starter:
                      starting_list += word_list[n+1]
      print 2                
      return starting_list
  
  
  
  def create_prefix_dict(word_list,prefix_length):
      while prefix &gt; 0:
          n = 0
          while n &lt; (len(word_list)-prefix):
              key = str(''.join(word_list[n]))
              if key in prefix_dict:
                  prefix_dict[key] += word_list[n+prefix]
              else:
                  prefix_dict[key] = word_list[n+prefix]
             n+=1
         key = ''
         prefix -=1
  
  print Markov_begin('Reacher.txt')
  </code></pre>