[FIXED] Mistaken, misleading, incorrect graphic in Python List Comprehension Article

Hello,
I believe there is a discrepancy here in the example with rainfall. The description doesn’t match the picture and the code provided. Could someone else give me feedback on this ? Did I miss something?

I believe the right midpoint to be 1.6/2, 0.8, so x2.

Blockquote The x-tick labels (the ones that say 2000, 2001, 2002, etc) were placed at each midpoint of the two bars. How did we calculate those x-values? The midpoint of 0.0 and 0.8 is 0.4, so that’s where the first tick should be. The midpoint of 2.0 and 2.8 is 2.4, so that’s where the second tick should be. Using a list comprehension:

Seen here: https://www.codecademy.com/paths/data-science/tracks/advanced-python/modules/ida-2-4-list-comprehension/articles/list-comprehension

1 Like

Hello, @javacoder31797, and welcome to the forums.

It definitely appears that the final output shown in your screenshot does not reflect the values presumably used in their example. Using the example code:

>>> xv1 = [2*i for i in range(5)]
>>> xv2 = [2*i + 0.8 for i in range(5)]
>>> xv1
[0, 2, 4, 6, 8]
>>> xv2
[0.8, 2.8, 4.8, 6.8, 8.8]
>>> xvm = [(x1 + x2)/2.0 for (x1, x2) in zip(xv1, xv2)]
>>> xvm 
[0.4, 2.4, 4.4, 6.4, 8.4] #these are the midpoints
>>>

Looks like a mistake to me. Thanks for pointing it out. I’ll report this to the CC team.

1 Like

Thanks again, @javacoder31797. The mistake in the article has been fixed.