Hi, so this is provided code in a section of the notebook we don’t have to write any code, so I think it is ‘okay’ to post:
Can someone please tell me what exactly is going on with the for _ in range(self.num_layers). I mean it is already contained within a list, and then, mysteriously there is this for-loop.
Yet no code to be in the loop comes after it. The list declaration just ends.
So if I understand you here, it produces self.num_layers of the EncoderLayers specified above it ?
That seems a little weird. Why doesn’t the for statement come first ? And does this technique work for any Python list or is it one of those weird TF things ?
And just by ‘weird Tensorflow thing’, I mean another mentor helped me with that but, for ex, they implement an expected def call function for example, but it was not clear to me at the time where on Earth that was coming from.
For additional context, the syntax you shared is called list comprehension in Python. It’s part of Python’s flair, it is more efficient than using a for loop.