<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Introduction to Python and Natural Language Technologies
Type system and built-in types
Errata and Q&A
19 September 2017
Errata
In this section, we shall fix some omissions from the lecture slides and try to clear up any confusion about certain concepts that we saw (or induced) during the lecture and the lab.
1. In-place sorting
In Python, the sorted() function can be used on any sequence to return a sorted list
Step1:  sorted() always returns a new object.
Step2:  It is also possible to sort lists in place with the sort() method of lists. It accepts the key and reverse parameters.
Step3:  2. Test for equality
It is worth noting that all built-in Python types support equality testing with the operator ==. The comparison is always by value. To test whether the two objects are the same, use id(o1) == id(o2).
Step4:  str, tuple and list also support &lt;, &lt;=, etc. set does too, but the semantics are different ($\subset$, $\subseteq$, ...)
3. Parameters of sorted()
There was a bit of confusion on the part of your lecturers about the cmp key for sorted(). To clear it up
<ASSISTANT_TASK:>
Python Code:
l1 = sorted(['b', 'c', 'a'])  # a list
l2 = sorted(('b', 'c', 'a'))  # a tuple
l3 = sorted('bca')  # a string
print(l1, l1 == l2 == l3)
print(type(l1) == type(l2) == type(l3) == list)
Explanation: Introduction to Python and Natural Language Technologies
Type system and built-in types
Errata and Q&A
19 September 2017
Errata
In this section, we shall fix some omissions from the lecture slides and try to clear up any confusion about certain concepts that we saw (or induced) during the lecture and the lab.
1. In-place sorting
In Python, the sorted() function can be used on any sequence to return a sorted list:
End of explanation
l = [1, 2, 3]
s = sorted(l)
print('This should be False:', id(l) == id(s))
Explanation: sorted() always returns a new object.
End of explanation
l = [2, 3, 1]
s = sorted(l)
print(l, s, l == s)  # l is unsorted, s is a new list
l.sort()
print(l, s, l == s)  # Now l is sorted
Explanation: It is also possible to sort lists in place with the sort() method of lists. It accepts the key and reverse parameters.
End of explanation
l1 = [1, 2, 3]
l2 = [1, 2, 3]
print(l1 == l2, id(l1) == id(l2))  # True, False
Explanation: 2. Test for equality
It is worth noting that all built-in Python types support equality testing with the operator ==. The comparison is always by value. To test whether the two objects are the same, use id(o1) == id(o2).
End of explanation
(1, 2, 3)[2] = 4
Explanation: str, tuple and list also support &lt;, &lt;=, etc. set does too, but the semantics are different ($\subset$, $\subseteq$, ...)
3. Parameters of sorted()
There was a bit of confusion on the part of your lecturers about the cmp key for sorted(). To clear it up: there is no cmp parameter in Python 3. It was available in Python 2, and it accepted a three-way comparison function, similar to how sorting is done in C, Java, Ruby, etc.
In contrast, Python 3 sorts by calling &lt;, just as C++ does.
More on sorting (advanced): https://docs.python.org/3/howto/sorting.html#sortinghowto
Q&A
Here we address some of the more interesting questions that you asked during the classes.
1. Immutability vs constness
The questions was whether immutability in Python is similar to C/C++'s keyword const. Superficially, these concepts seem similar, as both mean that the value of an object cannot be changed. However, the answer is "mostly not".
In a nutshell, constness is the property of the reference (or pointer); immutability is the property of the object itself. As there is no const in Python, the examples below are from C++. If you are only interested in Python, just skip this question.
In C++, const is used in two context:
Regulate write access to mutable objects
Define constants
1. Write access to mutable objects
```C++
void change_value_m(MutableObject& mref) {
  mref.set(2);  // This modifies the object's value
}
void change_value_c(MutableObject const& cref) {
  cref.set(3);  // Compilation error
}
int main(int argc, char* argv[]) {
  MutableObject mo(1);
  change_value_m(mo);
  change_value_c(mo);
  std::cout << mo.get() << std::endl;
}
```
However, the constness of a reference can be cast away:
C++
void change_value_c2(MutableObject const&amp; cref) {
  MutableObject&amp; mref = const_cast&lt;MutableObject&amp;&gt;(cref);
  mref.set(3);  // This works
}
On the other hand, if an object is immutable, it does not even have a set() or operator=() method:
```C++
class ImmutableObject {
  int value_;  // The value is hidden inside the object
public:
  ImmutableObject(int value) : value_(value) {}
  int get() { return value_; }
};
```
This is also how the Python tuple is made immutable. "Item assignment" in the error message below refers to the (lack of the) __setitem__ function (see next lecture).
End of explanation
<END_TASK>