Create a Tuple in a Linq Select

While the answer by octavioccl works, it’s better to first project the query result into anonymous type, and then switch to enumerable and convert it to tuple. This way your query will retrieve from the data base only the fields needed. codes = codesRepo.SearchFor(predicate) .Select(c => new { c.Id, c.Flag }) .AsEnumerable() .Select(c => new … Read more

Why is the use of tuples in C++ not more common?

A cynical answer is that many people program in C++, but do not understand and/or use the higher level functionality. Sometimes it is because they are not allowed, but many simply do not try (or even understand). As a non-boost example: how many folks use functionality found in <algorithm>? In other words, many C++ programmers … Read more

How to find the maximum value in a list of tuples? [duplicate]

Use max():   Using itemgetter(): In [53]: lis=[(101, 153), (255, 827), (361, 961)] In [81]: from operator import itemgetter In [82]: max(lis,key=itemgetter(1))[0] #faster solution Out[82]: 361 using lambda: In [54]: max(lis,key=lambda item:item[1]) Out[54]: (361, 961) In [55]: max(lis,key=lambda item:item[1])[0] Out[55]: 361 timeit comparison: In [30]: %timeit max(lis,key=itemgetter(1)) 1000 loops, best of 3: 232 us per … Read more

Python convert tuple to string

Use str.join: >>> tup = (‘a’, ‘b’, ‘c’, ‘d’, ‘g’, ‘x’, ‘r’, ‘e’) >>> ”.join(tup) ‘abcdgxre’ >>> >>> help(str.join) Help on method_descriptor: join(…) S.join(iterable) -> str Return a string which is the concatenation of the strings in the iterable. The separator between elements is S. >>>

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