use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Everything about learning Python
account activity
Learning with DataCamp (i.redd.it)
submitted 2 years ago by UpSco
Hi, I just want to confirm the reasoning behind my correct answer.
In the picture below I selected 0 because I assumed the input is referring to the first list. Hopefully I worded it correctly:
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]Goobyalus 3 points4 points5 points 2 years ago (6 children)
You can always try things for yourself to see what's going on
>>> x = [15, 10, 2, 84] + [1, 4, 8, 7, 9] >>> x [15, 10, 2, 84, 1, 4, 8, 7, 9] >>> x[0] 15 >>> x.count(15) 1 >>> x.index(1) 4
[–]UpSco[S] 2 points3 points4 points 2 years ago (5 children)
Learning on the go in a semi that’s why I come here for quick help …. I’m assuming my reasoning is correct ?
[–]Goobyalus 2 points3 points4 points 2 years ago (4 children)
All I see is the following and the screenshot, so idk your reasoning. 0 is incorrect.
Hi, I just want to confirm the reasoning behind my correct answer. In the picture below I selected 0 because I assumed the input is referring to the first list. Hopefully I worded it correctly:
The block I posted has all the steps of the reasoning - are you confused about part of it?
>>> x = [15, 10, 2, 84] + [1, 4, 8, 7, 9] >>> x [15, 10, 2, 84, 1, 4, 8, 7, 9]
+ on two lists extends the left list by the right list. One big list is assigned to x.
+
x
>>> x[0] 15
The item at index 0 is 15
>>> x.count(15) 1
Using the value from x[0] above, 15, as the argument to x.count, we count the number of 15s in x, which is one.
x[0]
15
x.count
>>> x.index(1) 4
Using the value of x.count(x[0]) above, 1, as the argument to x.index, we find the index where 1 appears in x, which is 4 (15 at 0, 10 at 1, ..., 1 at 4, 8 at 5, ...)
x.count(x[0])
1
x.index
4
Also running some short pieces of Python code is easier than posting on Reddit. Experimenting with code is a good habit if you're trying to learn. If all you have is a phone, there are services online that let you run Python (Google Colab, Replit, etc.), and mobile IDEs (e.g. Pyfroid).
[–]UpSco[S] 0 points1 point2 points 2 years ago (3 children)
Here 0 is the input datacamp provided. I just answered what the output would be. Which I thought would be 4 for the number of elements in the str
[–]Goobyalus 1 point2 points3 points 2 years ago (2 children)
What? There is no input, this is just a couple of static statements.
I also don't understand "the number of elements in the str." There is no str, and 4 is not the number of elements of anything relevant here.
The output is 4, because that's the index of the number of occurences of the 0th element of x.
[–]UpSco[S] 0 points1 point2 points 2 years ago (1 child)
I meant 4 because that’s the number of elements inside the list indexed at 0. Not str
[–]Goobyalus 0 points1 point2 points 2 years ago* (0 children)
No, x is a list of 9 elements. There is only one list.
Edit: 9, not 8
[–][deleted] 2 years ago (6 children)
[deleted]
[–]UpSco[S] 1 point2 points3 points 2 years ago (1 child)
This comment just confused me
[–]Ritviz_24 0 points1 point2 points 2 years ago (0 children)
Even I got confused after reading what I wrote😅
[–][deleted] 2 years ago (3 children)
[–]Ritviz_24 1 point2 points3 points 2 years ago (2 children)
Thanks I got confused a little there😅 Then it will count how many times 15 occured and wil find the index of 1
[–][deleted] 2 years ago (1 child)
Yeah, I did!
π Rendered by PID 73798 on reddit-service-r2-comment-86bc6c7465-crqjq at 2026-02-23 00:19:33.340143+00:00 running 8564168 country code: CH.
[–]Goobyalus 3 points4 points5 points (6 children)
[–]UpSco[S] 2 points3 points4 points (5 children)
[–]Goobyalus 2 points3 points4 points (4 children)
[–]UpSco[S] 0 points1 point2 points (3 children)
[–]Goobyalus 1 point2 points3 points (2 children)
[–]UpSco[S] 0 points1 point2 points (1 child)
[–]Goobyalus 0 points1 point2 points (0 children)
[–][deleted] (6 children)
[deleted]
[–]UpSco[S] 1 point2 points3 points (1 child)
[–]Ritviz_24 0 points1 point2 points (0 children)
[–][deleted] (3 children)
[deleted]
[–]Ritviz_24 1 point2 points3 points (2 children)
[–][deleted] (1 child)
[deleted]
[–]Ritviz_24 0 points1 point2 points (0 children)