Round2 Interview Question
In the interview , for a company (energy investments / commodities) a panel of 3 interviewers asked me the following during a discussion . Panel: Let's talk about some important Python details. It's ok if you don't remember things. Just an approximate answer will be fine for us. So, in Python, what is the difference between a List comprehension and a Generator expression. In a few words... Correct answer: A generator expression is like a list comprehension, except that it doesn't store the list in memory. Panel: Give some example . Write here in the tablet. Answer: list comprehension: simulated_returns = [price * volatility for price in historical_data] portfolio_value = sum(simulated_returns) generator: simulated_returns = (price * volatility for price in historical_data) portfolio_value = sum(simulated_returns)