Why Tuple’s items are ReadOnly?

Tuples originated in functional programming. In (purely) functional programming, everything is immutable by design – a certain variable only has a single definition at all times, as in mathematics. The .NET designers wisely followed the same principle when integrating the functional style into C#/.NET, despite it ultimately being a primarily imperative (hybrid?) language. Note: Though … Read more

Is there a name for this tuple-creation idiom?

I think this is a subtle implementation of a Monad-like thing, specifically something in the same spirit of the continuation monad. Monads are a functional programming construction used to simulate state between different steps of a computation (Remember that a functional language is stateless). What a monad does is to chain different functions, creating a … Read more

List of Tuples to DataFrame Conversion [duplicate]

I think this is what you want: >>> data = [(‘2013-01-16’, ‘AAPL’, 1), (‘2013-01-16’, ‘GOOG’, 1.5), (‘2013-01-17’, ‘GOOG’, 2), (‘2013-01-17’, ‘MSFT’, 4), (‘2013-01-18’, ‘GOOG’, 3), (‘2013-01-18’, ‘MSFT’, 3)] >>> df = pd.DataFrame(data, columns=[‘date’, ‘ticker’, ‘value’]) >>> df date ticker value 0 2013-01-16 AAPL 1.0 1 2013-01-16 GOOG 1.5 2 2013-01-17 GOOG 2.0 3 2013-01-17 MSFT … Read more

Why do we need tuples in Python (or any immutable data type)?

immutable objects can allow substantial optimization; this is presumably why strings are also immutable in Java, developed quite separately but about the same time as Python, and just about everything is immutable in truly-functional languages. in Python in particular, only immutables can be hashable (and, therefore, members of sets, or keys in dictionaries). Again, this … Read more

What’s the difference between lists enclosed by square brackets and parentheses in Python?

Square brackets are lists while parentheses are tuples. A list is mutable, meaning you can change its contents: >>> x = [1,2] >>> x.append(3) >>> x [1, 2, 3] while tuples are not: >>> x = (1,2) >>> x (1, 2) >>> x.append(3) Traceback (most recent call last): File “<stdin>”, line 1, in <module> AttributeError: … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)