data.frame rows to a list

Like this: xy.list <- split(xy.df, seq(nrow(xy.df))) And if you want the rownames of xy.df to be the names of the output list, you can do: xy.list <- setNames(split(xy.df, seq(nrow(xy.df))), rownames(xy.df))

Convert a Scala list to a tuple?

You can’t do this in a typesafe way. Why? Because in general we can’t know the length of a list until runtime. But the “length” of a tuple must be encoded in its type, and hence known at compile time. For example, (1,’a’,true) has the type (Int, Char, Boolean), which is sugar for Tuple3[Int, Char, … Read more

Elixir lists interpreted as char lists

Elixir has two kinds of strings: binaries (double quoted) and character lists (single quoted). The latter variant is inherited from Erlang and is internally represented as a list of integers, which map to the codepoints of the string. When you use functions like inspect and IO.inspect, Elixir tries to be smart and format a list … Read more

Prolog union for A U B U C

union(A, B, C, U) :- union(A, B, V), union(C, V, U). Your definition of union/3 can be improved by replacing … not(element(X,L)), … by … maplist(dif(X),L), … or … non_member(X, L), …. non_member(_X, []). non_member(X, [E|Es]) :- dif(X, E), non_member(X, Es). Here is a case where the difference shows: ?- union([A],[B],[C,D]). A = C, B … Read more

prolog change show answer to print into list

When describing a list, always consider using DCGs. In your case, you can very easily obtain what you want with a few simple modifications to your code: show_result(Squares,MaxRow,MaxCol, List) :- phrase(show_result(Squares,MaxRow,MaxCol,1), List). show_result(_,MaxRow,_,Row) –> { Row > MaxRow }, !. show_result(Squares,MaxRow,MaxCol,Row) –> { phrase(show_result(Squares,MaxRow,MaxCol,Row,1), Line) } , [Line], { Row1 is Row+1 }, show_result(Squares,MaxRow,MaxCol,Row1). show_result(_,_,MaxCol,_,Col) … Read more