create account

My Coding Quiz #61 by eniolw

View this thread on: hive.blogpeakd.comecency.com
· @eniolw ·
$15.46
My Coding Quiz #61
<div class="text-justify">

<center><h2>My Coding Quiz #61 👨‍💻🛠️🧩</h2></center>

<p>Welcome to the new installment of my series of <b>Coding Quizzes</b>, 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 <a href="/@eniolw">my blog</a> here on Hive and the <a href="/@eniolw/my-coding-quiz-1">first post</a> where I introduced it.</p>

<h3>Without further ado, here's the riddle...</h3>

<br>
<center>
<img src="https://images.ecency.com/DQmPG47CnWrdUvz4RWB47RbzAB3r2Jn7yXZaCC3mGjEDoWP/imagen.png" alt="Quiz">
<h6>By @eniolw</h6>
</center>

<br><center><h3>What's your choice?</h3></center>

<p><b>Solution to the <a href="/@eniolw/my-coding-quiz-60">previous quiz</a>:</b> <b>a1 1</b> Between lines 1 and 4 we are simply creating a dictionary using the <i>comprehension notation</i>.</p>

<p>Although this notation which spans seveal lines looks strange to some and is discouraged by others, it seems to be necessary when the line of code is very long, so it would fit well to span several lines. I personally like it and find it easily readable. Programmers in other languages are sometimes confused by this notation, but they soon get the hang of it.</p>

<p>As we can see, <code>r: f"{f}{r}"</code> is what defines the keys and values of the dictionary. The variable <code>r</code> is from the for loop we see below, while the f-string also makes use of <code>r</code> and another variable <code>f</code> which also changes value at each interaction. Here <code>f</code> and <code>r</code> stand for file and rank.</p>

<p>We see that the values of <code>r</code> and <code>f</code> start from <code>zip("abcde", range(1,5))</code>. We know that this <code>zip</code> function traverses two iterables at the same time. The first iterable is the string <code>"abcde"</code> of length 5, but the second iterable is <code>range(1,5)</code> which decomposed consists of 1,2,3,4, meaning its length is 4.</p>

<p>That tells us that the dictionary <code>d</code> will actually be formed like this: <b>{1: 'a1', 2: 'b2', 3: 'c3', 4: 'd4'}</b>. The pair <b>5: 'e5'</b> does not exist, since we already know that the <code>5</code> in the <code>range</code> is exclusive. This already helps us to rule out some of the options given for the quiz, such as the option <b>a1 e5</b>. The content of this dictionary, by the way, is <i>an analogy to the squares of a long diagonal of the chessboard</i>.</p>

<p>Once the dictionary is created, line 5 applies the <code>pop</code> method to it. Did you think this method only existed for lists? No, dictionaries also support it. How does it work in this case? Well, the first value we provide to the method corresponds to a key in the dictionary, while the next value is a <i>default value that pop will return in case the given key does not exist in the dictionary</i>, similar to how the <code>get</code> method works.</p>

<p>Although the <code>pop</code> method receives the key searched, it actually returns the value corresponding to that key. Hence in our case, when doing: <code>d1, d2 = d.pop(1, 0), d.pop(5, 1)</code>, <code>d1</code> will have the value <b>'a1'</b>, since key <b>1</b> exists and has the value <b>'a1'</b>, while <code>d2</code> will have the value <b>1</b>, which is the default value given to <code>pop</code>, since key <b>5</b> does not exist in the dictionary <code>d</code>.</p>

<p>By the way, you should know that the <code>pop</code> method is destructive, that is, it overwrites the dictionary, in this case removing key/values.</p>

<p>Finally when printing <code>d1</code> and <code>d2</code> we get that the output is <b>'a1 1'</b>, as expected.</p>

<hr>

<p>If you want to blog about computer science and programming content, I invite you to join <a href="/">Hive</a> and participate in its communities, such as <a href="/created/hive-196387">STEM-social</a>, <a href="/created/hive-154226">Develop Spanish</a>, <a href="/created/hive-169321">Programming & Dev</a> and others.</p>

<hr>

<center><h2>Mi Quiz de Programación #61 👨‍💻🛠️🧩</h2></center>

<p>Bienvenido a mi nueva serie de <b>Quizzes de Programación</b>, 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 <a href="/@eniolw">mi blog</a> aquí en Hive y el <a href="/@eniolw/my-coding-quiz-1">primer post</a> donde la presenté.</p>

<h3>Sin más preámbulos, he aquí el acertijo...</h3>

<br>
<center>
<img src="https://images.ecency.com/DQmVEtmXtbbApU3sMoMWW3bo5XypzyttUrLxrb7LdtVLTTK/imagen.png" alt="Quiz">
<h6>Por @eniolw</h6>
</center>

<br><center><h3>¿Cuál es tu elección?</h3></center>

<p><b>Solución al <a href="/@eniolw/my-coding-quiz-60">quiz anterior</a>:</b> <b>a1 1</b> Entre las líneas 1 y 4 simplemente estamos creando un diccionario usando la <i>notación de comprensión</i>.</p>

<p>Aunque esta notación que abarca varias líneas parece extraña para algunos y otros la desaconsejan, parece ser necesaria cuando la línea de código es muy larga, por lo que encajaría bien el abarcar varias líneas. A mí personalmente me gusta y lo encuentro fácil de leer. Los programadores de otros lenguajes a veces se sienten confundidos por esta notación, pero pronto le toman el hilo.</p>

<p>Como podemos ver, <code>r: f"{f}{r}"</code> es lo que define las claves y valores del diccionario. La variable <code>r</code> es del bucle for que vemos a continuación, mientras que la cadena f también hace uso de <code>r</code> y otra variable <code>f</code> que también cambia valor en cada interacción. Aquí <code>f</code> y <code>r</code> representan file (columna) y rank (fila).</p>

<p>Vemos que los valores de <code>r</code> y <code>f</code> comienzan desde <code>zip("abcde", range(1,5))</code>. Sabemos que esta función <code>zip</code> atraviesa dos iterables al mismo tiempo. El primer iterable es la cadena <code>"abcde"</code> de longitud 5, pero el segundo iterable es <code>range(1,5)</code> que descompuesto consta de 1,2,3,4, lo que significa que su longitud es 4.</p>

<p>Eso nos dice que el diccionario <code>d</code> en realidad se formará así: <b>{1: 'a1', 2: 'b2', 3: 'c3', 4: 'd4'}</b>. El par <b>5: 'e5'</b> no existe, ya que ya sabemos que el <code>5</code> en el <code>range</code> es exclusivo. Esto ya nos ayuda a descartar algunas de las opciones dadas para el quiz, como por ejemplo la opción <b>a1 e5</b>. El contenido de este diccionario, por cierto, es <i>una analogía con las casillas de una gran diagonal del tablero de ajedrez</i>.</p>

<p>Una vez creado el diccionario, la línea 5 le aplica el método <code>pop</code>. ¿Pensabas que este método sólo existía para listas? No, los diccionarios también lo admiten. ¿Cómo funciona en este caso? Bueno, el primer valor que proporcionamos al método corresponde a una clave en el diccionario, mientras que el siguiente valor es un <i>valor predeterminado que pop devolverá en caso de que la clave dada no exista en el diccionario</i>, similar cómo funciona el método <code>get</code>.</p>

<p>Aunque el método <code>pop</code> recibe la clave buscada, en realidad devuelve el valor correspondiente a esa clave. Por lo tanto en nuestro caso, al hacer: <code>d1, d2 = d.pop(1, 0), d.pop(5, 1)</code>, <code>d1</code> tendrá el valor <b>'a1'</b>, ya que la clave <b>1</b> existe y tiene el valor <b>'a1'</b>, mientras que <code>d2</code> tendrá el valor <b>1</b>, que es el valor predeterminado dado a <code>pop</code>, ya que la clave <b>5</b> no existe en el diccionario <code>d</code>.</p>

<p>Por cierto, debes saber que el método <code>pop</code> es destructivo, es decir, sobrescribe el diccionario, en este caso eliminando claves/valores.</p>

<p>Finalmente, al imprimir <code>d1</code> y <code>d2</code> obtenemos que la salida es <b>'a1 1'</b>, como se esperaba.</p>

<hr>

<p>Si quieres bloguear sobre contenido informático y de programación, te invito a unirte a <a href="/">Hive</a> y participar en sus comunidades, tales como <a href="/created/hive-196387">STEM-social</a>, <a href="/created/hive-154226">Develop Spanish</a>, <a href="/created/hive-169321">Programming & Dev</a> y otras.</p>

</div>
👍  , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , and 651 others
properties (23)
authoreniolw
permlinkmy-coding-quiz-61
categoryhive-197685
json_metadata"{"app":"ecency/3.2.0-vision","tags":["hive-197685","programming","coding","python","quiz","chess","neoxian","proofofbrain","waivio","creativecoin","spanish","ecency"],"format":"markdown+html","image":["https://images.ecency.com/DQmPG47CnWrdUvz4RWB47RbzAB3r2Jn7yXZaCC3mGjEDoWP/imagen.png","https://images.ecency.com/DQmVEtmXtbbApU3sMoMWW3bo5XypzyttUrLxrb7LdtVLTTK/imagen.png"],"thumbnails":["https://images.ecency.com/DQmPG47CnWrdUvz4RWB47RbzAB3r2Jn7yXZaCC3mGjEDoWP/imagen.png","https://images.ecency.com/DQmVEtmXtbbApU3sMoMWW3bo5XypzyttUrLxrb7LdtVLTTK/imagen.png"],"description":"My Coding Quiz #61 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 fun way.","image_ratios":["1.1737","1.1737"]}"
created2024-06-02 00:24:33
last_update2024-06-02 00:24:33
depth0
children5
last_payout2024-06-09 00:24:33
cashout_time1969-12-31 23:59:59
total_payout_value7.782 HBD
curator_payout_value7.679 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length8,278
author_reputation257,498,947,129,554
root_title"My Coding Quiz #61"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id134,132,393
net_rshares37,032,102,044,294
author_curate_reward""
vote details (715)
@hivebuzz ·
Congratulations @eniolw! You have completed the following achievement on the Hive blockchain And have been rewarded with New badge(s)

<table><tr><td><img src="https://images.hive.blog/60x70/https://hivebuzz.me/@eniolw/upvoted.png?202406020531"></td><td>You received more than 180000 upvotes.<br>Your next target is to reach 190000 upvotes.</td></tr>
</table>

<sub>_You can view your badges on [your board](https://hivebuzz.me/@eniolw) and compare yourself to others in the [Ranking](https://hivebuzz.me/ranking)_</sub>
<sub>_If you no longer want to receive notifications, reply to this comment with the word_ `STOP`</sub>



**Check out our last posts:**
<table><tr><td><a href="/hive-122221/@hivebuzz/pud-202406-feedback"><img src="https://images.hive.blog/64x128/https://i.imgur.com/zHjYI1k.jpg"></a></td><td><a href="/hive-122221/@hivebuzz/pud-202406-feedback">Feedback from the June Hive Power Up Day</a></td></tr><tr><td><a href="/hive-122221/@hivebuzz/pum-202405-result"><img src="https://images.hive.blog/64x128/https://i.imgur.com/mzwqdSL.png"></a></td><td><a href="/hive-122221/@hivebuzz/pum-202405-result">Hive Power Up Month Challenge - May 2024 Winners List</a></td></tr><tr><td><a href="/hive-122221/@hivebuzz/pum-202406"><img src="https://images.hive.blog/64x128/https://i.imgur.com/M9RD8KS.png"></a></td><td><a href="/hive-122221/@hivebuzz/pum-202406">Be ready for the June edition of the Hive Power Up Month!</a></td></tr></table>
properties (22)
authorhivebuzz
permlinknotify-1717306976
categoryhive-197685
json_metadata{"image":["https://hivebuzz.me/notify.t6.png"]}
created2024-06-02 05:42:57
last_update2024-06-02 05:42:57
depth1
children0
last_payout2024-06-09 05:42:57
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length1,449
author_reputation369,668,395,089,159
root_title"My Coding Quiz #61"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id134,135,453
net_rshares0
@miriannalis ·
@tipu curate 8
properties (22)
authormiriannalis
permlinkre-eniolw-seh29x
categoryhive-197685
json_metadata{"tags":["hive-197685"],"app":"peakd/2024.5.6"}
created2024-06-02 21:27:21
last_update2024-06-02 21:27:21
depth1
children1
last_payout2024-06-09 21:27:21
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length14
author_reputation308,525,647,930,579
root_title"My Coding Quiz #61"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id134,150,622
net_rshares0
@tipu ·
<a href="https://tipu.online/hive_curator?miriannalis" target="_blank">Upvoted  &#128076;</a> (Mana: 0/75) <a href="https://peakd.com/hive/@reward.app/reward-app-quick-guide-updated" target="_blank">Liquid rewards</a>.
properties (22)
authortipu
permlinkre-re-eniolw-seh29x-20240602t212726z
categoryhive-197685
json_metadata"{"app": "beem/0.24.26"}"
created2024-06-02 21:27:24
last_update2024-06-02 21:27:24
depth2
children0
last_payout2024-06-09 21:27:24
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length218
author_reputation55,949,689,035,458
root_title"My Coding Quiz #61"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id134,150,625
net_rshares0
@pibara ·
Hive Archeology comment
This is a [hive-archeology](https://github.com/pibara/hive-archeology) proxy comment meant as a proxy for upvoting good content that is past it's initial pay-out window.

![image.png](https://files.peakd.com/file/peakd-hive/pibara/EppQ5vutzcx8r5YZ2LiXjW7EnMtgkcam6KpByUfiojAYYXLBmKFTC1jom5Kig1H9Z1w.png)

<sub><sup>Pay-out for this comment is configured as followed:</sup></sub>

| <sub><sup>role</sup></sub> | <sub><sup>account</sup></sub> | <sub><sup>percentage</sup></sub> | <sub><sup>note</sup></sub>|
| --- | --- | --- | --- |
| <sub><sup>curator</sup></sub> | <sub><sup>-</sup></sub> | <sub><sup>0.0%</sup></sub> | <sub><sup>curation rewards disabled</sup></sub> |
| <sub><sup>dev</sup></sub> | <sub><sup>@croupierbot</sup></sub> | <sub><sup>2.5%</sup></sub> | <sub><sup>author of hive-archology</sup></sub> |
| <sub><sup>dev</sup></sub> | <sub><sup>@emrebeyler</sup></sub> | <sub><sup>2.5%</sup></sub> | <sub><sup>author of lighthive</sup></sub> |
| <sub><sup>author</sup></sub> | <sub><sup>@eniolw</sup></sub> | <sub><sup>95.0%</sup></sub> | <sub><sup></sup></sub> |
👍  
properties (23)
authorpibara
permlinkeniolw-my-coding-quiz-61
categoryhive-197685
json_metadata"{"tags": ["hivearcheology"], "app": "HiveArcheology 0.1.7"}"
created2024-06-28 08:06:42
last_update2024-06-28 08:06:42
depth1
children0
last_payout2024-07-05 08:06:42
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length1,075
author_reputation60,469,629,952,622
root_title"My Coding Quiz #61"
beneficiaries
0.
accountcroupierbot
weight250
1.
accountemrebeyler
weight250
2.
accounteniolw
weight9,500
max_accepted_payout1,000.000 HBD
percent_hbd0
post_id134,935,464
net_rshares279,221,840,934
author_curate_reward""
vote details (1)
@stemsocial ·
re-eniolw-my-coding-quiz-61-20240603t172348419z
<div class='text-justify'> <div class='pull-left'>
 <img src='https://stem.openhive.network/images/stemsocialsupport7.png'> </div>

Thanks for your contribution to the <a href='/trending/hive-196387'>STEMsocial community</a>. Feel free to join us on <a href='https://discord.gg/9c7pKVD'>discord</a> to get to know the rest of us!

Please consider delegating to the @stemsocial account (85% of the curation rewards are returned).

You may also include @stemsocial as a beneficiary of the rewards of this post to get a stronger support.&nbsp;<br />&nbsp;<br />
</div>
properties (22)
authorstemsocial
permlinkre-eniolw-my-coding-quiz-61-20240603t172348419z
categoryhive-197685
json_metadata{"app":"STEMsocial"}
created2024-06-03 17:23:48
last_update2024-06-03 17:23:48
depth1
children0
last_payout2024-06-10 17:23:48
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length565
author_reputation22,928,473,369,679
root_title"My Coding Quiz #61"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id134,170,724
net_rshares0