title: 'list' object has no attribute 'foreach'
body: <p>I am trying to replicate <a href="https://spark.apache.org/docs/latest/rdd-programming-guide.html#printing-elements-of-an-rdd" rel="nofollow noreferrer">the given code</a> to see how <code>foreach</code> works, I tried with the following code:</p>
  <pre><code>rdd = sc.parallelize([1,2,3,4,5])
  
  def f(a):
      print(a)
  
  rdd.collect().foreach(f)
  </code></pre>
  <p>But it gives the following error:</p>
  <blockquote>
  <p>AttributeError: 'list' object has no attribute 'foreach'</p>
  </blockquote>
  <p>I understand the error that return type of <code>collect()</code> is a <code>array</code>(which is list) and it doesn't have <code>foreach</code> attribute associated with it but, I don't understand how this doesn't work if it's given in the official <code>spark 3.0.1</code> documentation. What am I missing. I am using <code>Spark 3.0.1</code></p>