4 ms·
Seems completely broken now; like others, I tried to test something, found I had to sign up, signed up, and found I have "0 free credits". I really wanted to s
by merlincorey 4y ago
Seems completely broken now; like others, I tried to test something, found I had to sign up, signed up, and found I have "0 free credits".
I really wanted to see what it was gonna do for Python -> C++ converting some nested dictionary and list comprehensions:
def foobar(x, y):
return {
_: __
for _, __ in zip(
[_ for _ in x if _ in y],
[_ for _ in x if _ not in y]
)
}
{3: 1, 4: 2} == foobar([1, 2, 3, 4], [3, 4, 5, 6])
- polygot 4y agoI bought some credits. Here is the result (Python to C++): std::map<int, int> foobar(std::vector<int> x, std::vector<int> y) { std::map<int, int> map; for (int i = 0; i < x.size(); i++) { if (std::find(y.begin(), y.end(), x[i]) != y.end()) { map[x[i]] = x[i + 1]; } } return map; }
- merlincorey 4y agoThanks for checking into that... doesn't look like the AI is even close to ready for prime time right now as this is not the correct translation: #include <algorithm> #include <iostream> #include <map> #include <vector> std::map<int, int> foobar(std::vector<int> x, std::vector<int> y) { std::map<int, int> map; for (int i = 0; i < x.size(); i++) { if (std::find(y.begin(), y.end(), x[i]) != y.end()) { map[x[i]] = x[i + 1]; } } return map; } int main(int argc, char** argv) { std::vector<int> ex{ 1, 2, 3, 4 }; std::vector<int> wy{ 3, 4, 5, 6 }; std::map<int, int> result = foobar(ex, wy); std::cout << "{"; for ( const auto &item : result) { std::cout << item.first << ": " << item.second << ", "; } std::cout << "}" << std::endl; } It outputs: {3: 4, 4: 0, } But it SHOULD be getting: {3: 1, 4: 2, }