title: How to broadcast RDD in PySpark?
body: <p>Is it possible to broadcast an RDD in Python? </p>
  
  <p>I am following the book "Advanced Analytics with Spark: Patterns for Learning from Data at Scale" and on chapter 3 an RDD needs to be broadcasted. I'm trying to follow the examples using Python instead of Scala.</p>
  
  <p>Anyway, even with this simple example I have an error:</p>
  
  <pre><code>my_list = ["a", "d", "c", "b"]
  my_list_rdd = sc.parallelize(my_list)
  sc.broadcast(my_list_rdd)
  </code></pre>
  
  <p>The error being:</p>
  
  <pre><code>"It appears that you are attempting to broadcast an RDD or reference an RDD from an "
  Exception: It appears that you are attempting to broadcast an RDD or reference an RDD from an
  action or transformation. RDD transformations and actions can only be invoked by the driver, n
  ot inside of other transformations; for example, rdd1.map(lambda x: rdd2.values.count() * x) i
  s invalid because the values transformation and count action cannot be performed inside of the
   rdd1.map transformation. For more information, see SPARK-5063.
  </code></pre>
  
  <p>I don't really understand what "action or transformation" the error is referring to.</p>
  
  <p>I am using <code>spark-2.1.1-hadoop2.7</code>.</p>
  
  <p><strong>Important Edit</strong>: the book is correct. I just failed to read that it wasn't an RDD that was being broadcasted but a map version of it obtained with collectAsMap().</p>
  
  <p>Thanks!</p>