labeled_alphabet = pd.Series(list(ascii_uppercase), index=map(lambda x: 'label_' + x, list(ascii_uppercase)))
def every_fifth(x):
return (True if (i+1) % 5 == 0 else False for i in range(x.size))
print(labeled_alphabet.iloc[every_fifth])
Since x is the input parameter how iloc is able to send the x without mentioning x in the function. For example I tried the following the code didnt error out but merely returned object.
<generator object every_fifth.<locals>.<genexpr> at 0x000001AE9E3E4F20>
Can someone explain what is happening here.
Also when to use [] and () This works
def every_fifth(x):
return (True if (i+1) % 5 == 0 else False for i in range(x.size))
and also this works too:
def every_fifth(x):
return [True if (i+1) % 5 == 0 else False for i in range(x.size)]
The moment I change to [] the above output is changed to [False, False, False, False, True, False, False, False, False, True, False, False, False, False, True, False, False, False, False, True, False, False, False, False, True, False] What is happening here.