+ 3

How this code is changing and adding new values? Want to understand this . Pls explain. Thanks in advance.

https://code.sololearn.com/c7kmtglbMJYV/?ref=app

12th Mar 2023, 8:56 AM
viswajeet
viswajeet - avatar
24 Antworten
+ 10
the miracle lies in line 4 for b[n] in a it means: iterate a and in each iteration assign the actual value to b[n] n is increased by one each time a : b c d n: 1 2 3 b[1] = b b[2]=c b[3] =d
12th Mar 2023, 9:02 AM
Oma Falk
Oma Falk - avatar
+ 10
Such and similar tasks appear occasionally. > I don't think codes like this have any practical relevance. they only serve to cause confusion in questions, interviews or challenges.
12th Mar 2023, 12:03 PM
Lothar
Lothar - avatar
+ 6
Prince Onyebuchi , > it is better for you to start your own post / question, otherwise poeple will not get aware of you. > give a helpful task description including input values and what output you are expecting. > please also include your current code in the post.
14th Mar 2023, 11:59 AM
Lothar
Lothar - avatar
+ 5
faisal tyagi , > you have posted 2 new questions inside a running and existing feed. this is not the way how questions should be published. > it is better for you to start your own post, otherwise poeple will not get aware of you and your question. > an other problem is: if the initial poster is going to delete his post, everything inside the post will be also deleted. in this case your questions are gone. > since i can not see that you have started to learn from a *python* tutorial, it is recommended to do so.
20th Mar 2023, 9:16 PM
Lothar
Lothar - avatar
+ 3
BTW print(dict(zip([1,2,3],"bcd")))
12th Mar 2023, 2:00 PM
Oma Falk
Oma Falk - avatar
+ 3
Ohhh. OK...as far as I remember there is a pipe module on pypi for our unixoids Bob_Li
12th Mar 2023, 2:14 PM
Oma Falk
Oma Falk - avatar
+ 3
Oma Falk, I asked because I was confused by the way the code is written.
12th Mar 2023, 3:54 PM
viswajeet
viswajeet - avatar
+ 3
Great community of sololearn. Really helpful. Whenever help required, mentors/members quickly resolve the problem. Thanks very much. Proud to be part of sololearn. 🙏🙏🙏🙏👌👍👍👍👍
12th Mar 2023, 3:58 PM
viswajeet
viswajeet - avatar
+ 2
first time I saw it used like this. Very interesting. usually, I would do a=['b','c','d'] b={1:'a'} for n,v in enumerate(a): b[n+1] = v print(b) "for b[n] in a" is really unusual. Feels like a cross between a regular conditional and list comprehension 😁
12th Mar 2023, 10:17 AM
Bob_Li
Bob_Li - avatar
+ 1
By the way, thanks to everyone to sort out this.
12th Mar 2023, 12:37 PM
viswajeet
viswajeet - avatar
+ 1
This type of code expand your knowledge. It may seem sometimes irrelevant to practical life, but it increases your coding ability. Isn't it. Once again, thanks all of you buddy for giving response so quickly. Have a great day and also great life.
12th Mar 2023, 12:40 PM
viswajeet
viswajeet - avatar
+ 1
But why so you ask? Obviously you knew the answer 🙄
12th Mar 2023, 1:43 PM
Oma Falk
Oma Falk - avatar
+ 1
Python's list, tuple and dictionary comprehensions are commonly used with range, enumerate, zip to create new objects.
12th Mar 2023, 1:49 PM
Bob_Li
Bob_Li - avatar
+ 1
Oma Falk nesting functions! 🤯 What sorcery is this?! 🤯
12th Mar 2023, 2:10 PM
Bob_Li
Bob_Li - avatar
+ 1
faisal tyagi what output do you need? Please elaborate.
20th Mar 2023, 3:56 PM
viswajeet
viswajeet - avatar
+ 1
Lothar you are absolutely right
21st Mar 2023, 7:52 AM
viswajeet
viswajeet - avatar
0
Lothar , you may be right, but still it is necessary to understand this type of codes as it will be useful when you reach upper level at software developer
12th Mar 2023, 12:36 PM
viswajeet
viswajeet - avatar
0
This code is binding value of dictionary to values of list. Please tell if there are more ways to bind value of one type to other. (Like list to dict, in this case) Thanks
12th Mar 2023, 1:16 PM
viswajeet
viswajeet - avatar
0
Boolean Logic Given the age of a person as an input, output their age group. Here are the age groups you need to handle: Child: 0 to 11 Teen: 12 to 17 Adult: 18 to 64 Sample Input 42 Sample Output Adult age=int(input ()) If age>0 and age<=11: Print("Child ") elif age>=12 and age<=17: Print("Teen") elif age>=18 and <=64: Print("Adult") This programme is not run. Where is error ....
12th Mar 2023, 8:58 PM
faisal tyagi
faisal tyagi - avatar
0
faisal tyagi the code is running smoothly. You had made some syntax mistakes.I have made necessary rectification. Just have a look and also practice more. Enjoy pythoning
13th Mar 2023, 4:13 AM
viswajeet
viswajeet - avatar