syntactic-sugar

How to unpack the columns of a pandas DataFrame to multiple variables

How to unpack the columns of a pandas DataFrame to multiple variables Question: Lists or numpy arrays can be unpacked to multiple variables if the dimensions match. For a 3xN array, the following will work: import numpy as np a,b = [[1,2,3],[4,5,6]] a,b = np.array([[1,2,3],[4,5,6]]) # result: a=[1,2,3], b=[4,5,6] How can I achieve a similar …

Total answers: 2

What does extended slice syntax actually do for negative steps?

What does extended slice syntax actually do for negative steps? Question: The extended slice syntax in python has been explained to me as “a[n:m:k] returns every kth element from n to m“. This gives me a good idea what to expect when k is positive. But I’m lost on how to interpret a[n:m:k] for negative …

Total answers: 2

Python decorators just syntactic sugar?

Python decorators just syntactic sugar? Question: Possible Duplicate: Understanding Python decorators I am quite new on using Python decorators and from what I understand on my first impression that they are just syntactic sugar. Is there a more profound use of them for more complex uses ? Asked By: coredump || Source Answers: I really …

Total answers: 2

Python decorator best practice, using a class vs a function

Python decorator best practice, using a class vs a function Question: As I’ve understood it there are two ways to do a Python decorator, to either use the __call__ of a class or to define and call a function as the decorator. What’s the advantages/disadvantages of these methods? Is there one preferred method? Example 1 …

Total answers: 4

Ignore an element while building list in python

Ignore an element while building list in python Question: I need to build a list from a string in python using the [f(char) for char in string] syntax and I would like to be able to ignore (not insert in the list) the values of f(x) which are equal to None. How can I do …

Total answers: 2

Elegant ways to return multiple values from a function

Elegant ways to return multiple values from a function Question: It seems like in most mainstream programming languages, returning multiple values from a function is an extremely awkward thing. The typical solutions are to make either a struct or a plain old data class and return that, or to pass at least some of the …

Total answers: 14