create account

My Coding Quiz #37 by eniolw

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

<center><h2>My Coding Quiz #37 馃懆鈥嶐煉火煕狅笍馃З</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/DQmbuZX5dzDmmrVannUAmep98VuvwBYKku5A3SaSgX5DtGY/quiz_img_en.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-36">previous quiz</a>:</b> <b>{'vote': True, 'comment': False, 'done': False}</b>. This script is a nod to the previous edition, as it suggests that it talks about curation.</p>

<p>We start by defining two dictionaries <code>d1</code> and <code>d2</code> that represent data. Then we define the function <code>is_done</code> where all the interesting stuff happens. Basically it returns a dictionary that is formed by combining two received dictionaries <code>a</code> and <code>b</code> and adding a new key <code>'done'</code>.</p>

<p>To combine the dictionaries we use the <i>unpack operator</i> (<code>**</code>) as it is in the code, which does exactly the same thing as the Javascript spread operator (<code>...</code>). Interestingly, this usage has been around in Python for a long time before JavaScript incorporated its spread operator. We also see that, as to be expected in dictionary merging, keys are overwritten, as in the case of <code>'comment'</code> in <code>a</code> which is <code>True</code>, but is overwritten by the value of <code>'comment'</code> in <code>b</code> which is <code>False</code>.</p>

<p>We can still define keys within the dictionary declaration, as in the case of <code>'done'</code>. Its value is obtained by applying the function <code>all</code> that evaluates if all the elements of the iterable are Truthy. We see that we give this function the list <code>[*a.values(), *b.values()]</code> that has been composed using the <i>unpack operator in lists</i> (<code>*</code>), which is also equivalent to the spread operator of Javascript applied to arrays.</p>

<p>We need to use the <code>values</code> method on <code>a</code> and <code>b</code> to get the iterables of the values in those dictionaries and these iterables are unpacked by the asterisk, so we get the list <b>[True, True, True, False]</b>. The function <code>all</code> will therefore return <code>False</code> because not all values in the list are truthy. In short, <code>is_done</code> returns the dictionary <b>{'vote': True, 'comment': False, 'done': False}</b> and is printed at the end.</p>

<p>As we can see, depending on what we want to merge or extend, in Python we must use <code>*</code> in case of lists and <code>**</code> in case of dictionaries. Most programmers are familiar with them in the context of the optional function parameters <code>*args</code> and <code>**kargs</code>, where in fact, they just follow the same principle, but their use can actually be applied beyond that and can enrich your code.</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 #37 馃懆鈥嶐煉火煕狅笍馃З</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/DQmdV9G32shXtVumWnd8jrTwxffWEUkMB4syd6hahWWcbXJ/quiz_img_es.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-36">quiz anterior</a>:</b> <b>{'vote': True, 'comment': False, 'done': False}</b>. Este script es un gui帽o a la edici贸n anterior, ya que sugiere que habla de curaci贸n.</p>

<p>Comenzamos definiendo dos diccionarios <code>d1</code> y <code>d2</code> que representan datos. Luego definimos la funci贸n <code>is_done</code> donde suceden todas las cosas interesantes. B谩sicamente devuelve un diccionario que se forma combinando dos diccionarios recibidos <code>a</code> y <code>b</code> y agregando una nueva clave <code>'done'</code>.</p>

<p>Para combinar los diccionarios utilizamos el <i>operador de desempaquetado</i> (<code>**</code>) tal como est谩 en el c贸digo, que hace exactamente lo mismo que el operador spread de Javascript (<code>...</code>). Curiosamente, este uso ha existido en Python durante mucho tiempo antes de que JavaScript incorporara su operador spread. Tambi茅n vemos que, como es de esperar en la combinaci贸n de diccionarios, las claves se sobrescriben, como en el caso de <code>'comment'</code> en <code>a</code> que es <code>True</code>, pero se sobrescribe con el valor de <code>'comment'</code> en <code>b</code> que es <code>False</code>.</p>

<p>No conforme con ello, podemos definir claves dentro de la declaraci贸n del diccionario, como en el caso de <code>'done'</code>. Su valor se obtiene aplicando la funci贸n <code>all</code> que eval煤a si todos los elementos del iterable son verdaderos. Vemos que le damos a esta funci贸n la lista <code>[*a.values(), *b.values()]</code> que ha sido compuesta usando el <i>operador desempaquetado en listas</i> (<code>*</code>), que tambi茅n es equivalente al operador de spread de Javascript aplicado a arreglos.</p>

<p>Necesitamos usar el m茅todo <code>values</code> en <code>a</code> y <code>b</code> para obtener los iterables de los valores en esos diccionarios y estos iterables se desempaquetan por el asterisco, por lo que obtenemos la lista <b>[True, True, True, False]</b>. Por lo tanto, la funci贸n <code>all</code> devolver谩 <code>False</code> porque no todos los valores de la lista son verdaderos. En resumen, <code>is_done</code> devuelve el diccionario <b>{'vote': True, 'comment': False, 'done': False}</b> y se imprime al final.</p>

<p>Como podemos ver, dependiendo de lo que queramos fusionar o extender, en Python debemos usar <code>*</code> en el caso de listas y <code>**</code> en el caso de diccionarios. La mayor铆a de los programadores est谩n familiarizados con ellos en el contexto de los par谩metros de funci贸n opcionales <code>*args</code> y <code>**kargs</code>, donde, de hecho, siguen el mismo principio, pero su uso puede variar y en realidad se puede aplicar m谩s all谩 de eso y puede enriquecer tu c贸digo.</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 596 others
properties (23)
authoreniolw
permlinkmy-coding-quiz-37
categoryhive-140084
json_metadata"{"image":["https://images.ecency.com/DQmbuZX5dzDmmrVannUAmep98VuvwBYKku5A3SaSgX5DtGY/quiz_img_en.png","https://images.ecency.com/DQmdV9G32shXtVumWnd8jrTwxffWEUkMB4syd6hahWWcbXJ/quiz_img_es.png"],"tags":["hive-140084","coding","python","javascript","quiz","programming","neoxian","proofofbrain","waivio","spanish"],"description":"My Coding Quiz #37 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.","app":"ecency/3.0.37-vision","format":"markdown+html","image_ratios":["0.9390","0.9390"]}"
created2023-11-29 02:03:18
last_update2023-11-29 02:03:18
depth0
children3
last_payout2023-12-06 02:03:18
cashout_time1969-12-31 23:59:59
total_payout_value4.008 HBD
curator_payout_value3.887 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length7,452
author_reputation258,087,764,706,776
root_title"My Coding Quiz #37"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id129,257,768
net_rshares16,712,194,364,021
author_curate_reward""
vote details (660)
@fc-curation ·
!DHEDGE
properties (22)
authorfc-curation
permlinkre-eniolw-20231130t155719382z
categoryhive-140084
json_metadata{"tags":["hive-140084","coding","python","javascript","quiz","programming","neoxian","proofofbrain","waivio","spanish"],"app":"ecency/3.0.37-vision","format":"markdown+html"}
created2023-11-30 10:57:30
last_update2023-11-30 10:57:30
depth1
children1
last_payout2023-12-07 10:57:30
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_length7
author_reputation61,419,996,141,932
root_title"My Coding Quiz #37"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id129,292,157
net_rshares0
@dhedge ·
Out Of Calls
you have 0.0 vote calls available today, your vote calls will reset at next snapshot. You can [buy DHEDGE on Tribaldex](https://tribaldex.com/trade/DHEDGE) or earn some daily by joining one of our many delegation pools at [app.dhedge.cc](https://app.dhedge.cc) to increase your daily amount.
properties (22)
authordhedge
permlinkre-re-eniolw-20231130t155719382z-20231130t105737z
categoryhive-140084
json_metadata"{"app": "beem/0.24.26"}"
created2023-11-30 10:57:36
last_update2023-11-30 10:57:36
depth2
children0
last_payout2023-12-07 10:57:36
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_length291
author_reputation5,003,962,900,629
root_title"My Coding Quiz #37"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id129,292,160
net_rshares0
@stemsocial ·
re-eniolw-my-coding-quiz-37-20231129t172830505z
<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 (23)
authorstemsocial
permlinkre-eniolw-my-coding-quiz-37-20231129t172830505z
categoryhive-140084
json_metadata{"app":"STEMsocial"}
created2023-11-29 17:28:30
last_update2023-11-29 17:28:30
depth1
children0
last_payout2023-12-06 17:28:30
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,930,909,407,157
root_title"My Coding Quiz #37"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id129,274,977
net_rshares789,475,407
author_curate_reward""
vote details (1)