Welcome to the new installment of my series of Coding Quizzes, in which you will be able to test your knowledge and skills about programming and software development in a simple and fun way. If you want to learn more about it visit my blog here on Hive and the first post where I introduced it.
Solution to the previous quiz: None, [-1, 4, 6]. In line 1 a list of numerical elements (a = [6, 4, -1]) is created and the same happens in line 2 (a = [1, 0]); nothing special so far.
Line 3 is where the heart of the matter lies. It contains: print(b.sort(), sorted(a)). The sort method is built-in to Python lists and what it does is to modify the list itself, in this case the one referenced with the identifier b. This function returns None. In contrast, the built-in sorted function returns a new list from an iterable. That is what differentiates the two functions. You probably knew it, because the previous post talked about it too. So None, [-1, 4, 6] is the expected output.
If you want to blog about computer science and programming content, I invite you to join Hive and participate in its communities, such as STEM-social, Develop Spanish, Programming & Dev, Hive Learners and others.
Bienvenido a mi nueva serie de Quizzes de Programaci贸n, en la cual podr谩s poner a prueba tus conocimientos y habilidades sobre programaci贸n y desarrollo de software de una manera sencilla y divertida. Si quieres aprender m谩s sobre ella visita mi blog aqu铆 en Hive y el primer post donde la present茅.
Soluci贸n al quiz anterior: None, [-1, 4, 6]. En la l铆nea 1 se crea una lista de elementos num茅ricos (a = [6, 4, -1]) y lo mismo ocurre en la l铆nea 2 (a = [1, 0]); nada especial hasta ahora.
La l铆nea 3 es la que contiene la esencia del asunto. Esta contiene: print(b.sort(), sorted(a)). El m茅todo sort est谩 integrado en las listas de Python y lo que hace es modificar la propia lista, en este caso aquella referenciada con el identificador b. Esa funci贸n retorna None. Por el contrario, la funci贸n integrada sorted retorna una nueva lista a partir de un iterable. Eso es lo que diferencia a ambas funciones. Probablemente lo sab铆as, pues adem谩s el anterior post hablaba de ello tambi茅n. De tal modo que None, [-1, 4, 6] es la salida esperada.
Si quieres bloguear sobre contenido inform谩tico y de programaci贸n, te invito a unirte a Hive y participar en sus comunidades, tales como STEM-social, Develop Spanish, Programming & Dev, Hive Learners y otras.