0

I don't know python I am working through 'Exercises in Programming Style' and translating to javascript. I can understand most of the python but this line flabbergasts me .

# Let's use the first 25 entries for the top 25 words
data = data + [[]]*(25 - len(data))

some context: the challenge is to use self imposed memory limitations represented here by the data array. So here she just cleared out data that is no longer used to make room for the 25 most frequent word. What is she doing here ?

MadMax
  • 605
  • 1
  • 6
  • 19
  • 1
    Err... it's a list that contains a list. – Ignacio Vazquez-Abrams May 07 '18 at 15:53
  • 4
    They *poorly* created a list of lists, while falling into the [common trap](https://stackoverflow.com/questions/5518435/python-fastest-way-to-create-a-list-of-n-lists) of making a list with many copies of the same inner lists – Cory Kramer May 07 '18 at 15:54
  • @CoryKramer I think in this case that might be *the point*, but it's not clear without the full exercise – Chris_Rands May 07 '18 at 15:56
  • https://github.com/crista/exercises-in-programming-style/blob/master/01-good-old-times/tf-01.py – MadMax May 07 '18 at 15:57
  • @madmax I'm not clear exactly *what* they are tying to show here, but I would say that is not the most modern idiomatic Python style – Chris_Rands May 07 '18 at 16:03
  • @Chris_Rands Thanks! the point of the exercise isn't to write good code it's supposed to be 'Old time style' where basically you have a very limited amount of RAM and no identifiers. In the book for that line it says 'keep an ordered listin memory holding the 25 most frequent words and their frequencies'. Wierd but cool. – MadMax May 07 '18 at 16:08

0 Answers0