|
|
|
c# linq Linq to Python
|
|
| Code: : | var stoogeGuys = Beginning with the _xml_ source from _xml_Guys in _xml_Source.Descendants( Stooge ) Join to the array on the common element stoogeName join arrayGuys in familyFacts on _xml_Guys.Element( stoogeName ).Value equals arrayGuys.stoogeName Join to the data_base_ on the common element stoogeName join dbGuys in stoogeContext.stoogeTables on _xml_Guys.Element( stoogeName ).Value equals dbGuys.stoogeName select new { firstName = dbGuys.stoogeName, familyName = arrayGuys.familyName, birthDate = _xml_Guys.Element( birthDate ).Value, deathDate = _xml_Guys.Element( deathDate ).Value, hairCut_style_ = dbGuys.stoogeHaircut, }; | It could e.g. look like this in Python: stoogeGuys = [] for _xml_Guys in _xml_Source.Descendants[ Stooge ]: arrayGuys = familyFacts[_xml_Guys.stoogeName] dbGuys = stoogeContext.stoogeTables[_xml_Guys.stoogeName] stoogeGuys += [{'firstName': dbGuys.stoogeName, 'familyName': arrayGuys.familyName, 'birthDate': _xml_Guys.birthDate, 'deathDate': dbGuys.deathDate, 'hairCut_style_': dbGuys.stoogeHaircut}]
|
|
|
|
|
|
|
The administrator has disabled public write access. |
|
|
|
c# linq Linq to Python
|
|
|
Pardon my ignorance again but id ont see any join in python or did i miss something ? It's more Pythonic to use the syntax of dictionary lookups.
|
|
|
|
|
|
|
The administrator has disabled public write access. |
|
|
|
c# linq Linq to Python
|
|
|
Pardon my ignorance again but id ont see any join in python or did i miss something ? It's more Pythonic to use the syntax of dictionary lookups.
|
|
|
|
|
|
|
The administrator has disabled public write access. |
|
|
|
c# linq Linq to Python
|
|
|
BTW, a minor correction: LINQ statements are closer to generators, not list comprehensions. They don't actually evaluate their results until you iterate over them and you can re-used the same LINQ statement multiple times getting different results if the data has changed. Python has generator _expression_s with the same syntax as list comprehensions, except you use () instead of []. It might surprise you to know that I have actually come across generator _expression_s. :^) My wording was deliberate: LINQ queries are re-usable, so are Python's generators, but generator _expression_s are not. The comparison isn't exact, you have to call the generator to get an iterator whereas a LINQ _expression_ gives you something which is directly iterable.
|
|
|
|
|
|
|
The administrator has disabled public write access. |
|
|
|
c# linq Linq to Python
|
|
|
No Python's syntax is fine. The api's aren't as consistent though: Microsoft added a common set of extension methods which work on data_base_s, _xml_, builtin sequences and can be easily extended to include other custom sequences. That is correct, but it is a library issue and cannot be solved by adding new syntax.
|
|
|
|
|
|
|
The administrator has disabled public write access. |
|
|
|
c# linq Linq to Python
|
|
|
Microsoft added a common set of extension methods which work on data_base_s, _xml_, builtin sequences and can be easily extended to include other custom sequences. When the processing is done in memory, LINQ may also work well with multi-core CPUs, see PLINQ. Bye, bearophile
|
|
|
|
|
|
|
The administrator has disabled public write access. |
|