+ 3
How this code is changing and adding new values? Want to understand this . Pls explain. Thanks in advance.
24 odpowiedzi
+ 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
+ 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.
+ 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.
+ 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.
+ 3
BTW print(dict(zip([1,2,3],"bcd")))
+ 3
Ohhh. OK...as far as I remember there is a pipe module on pypi for our unixoids
Bob_Li
+ 3
Oma Falk, I asked because I was confused by the way the code is written.
+ 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. 🙏🙏🙏🙏👌👍👍👍👍
+ 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 😁
+ 1
By the way, thanks to everyone to sort out this.
+ 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.
+ 1
But why so you ask? Obviously you knew the answer 🙄
+ 1
Python's list, tuple and dictionary comprehensions are commonly used with range, enumerate, zip to create new objects.
+ 1
Oma Falk
nesting functions!
🤯 What sorcery is this?! 🤯
+ 1
faisal tyagi what output do you need? Please elaborate.
+ 1
Lothar you are absolutely right
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
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
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 ....
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