Similar Posts

Subscribe
Notify of
4 Answers
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
McHusky
1 year ago

So the Python Script builds an array with the numbers of 0-9. The array is then sorted with the Sort method and then output.

I don’t know how to do this in C++ or Java. It’s probably more complicated there. So that you have to use a Bubble Sort method with auxiliary variable or otherwise as gross.

I don’t think the Meme is funny now.

medmonk
1 year ago

In Python only two-three lines are required, while in C++ and Java you have to do more for the same result. Be iterated by a for loop and then output it. The “Witz” is probably aimed at it.

Python:

arr = [5, 3, 2, 1, 6, 8, 9, 0]
arr.sort()
print(arr)

C++:

int main() {
  std::vector vec = {5, 3, 2, 1, 6, 8, 9, 0};
  std::sort(vec.begin(), vec.end());

  for (int num : vec) {
    std::cout << num << " ";
  }

 return 0;
}
KarlRanseierIII
1 year ago

The real irony is that in Python it is also so:

print(sorted([8,2,3,9,1,6,4,5,7]))

While it becomes more extensive in languages like C++ and Java, simply because lists like std::list at C++ are not intrinsic types. In addition, the often cryptic syntax comes.

But this becomes really clear only with less trivial examples:

jort93
1 year ago

Honestly, I don’t think funny, but I think that’s what it takes a few more lines in languages.

import java.util.Arrays; 
public class MyClass {
    public static void main(String args[]) {
        int[] arr = { 5, -2, 23, 7, 87, -42, 509 };
        Arrays.sort(arr);      
        System.out.println(Arrays.toString(arr));
    }
}

But good, I’m talking where that’s even more complex.