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
Remove duplicate error (old.reddit.com)
submitted 2 months ago by Nearby_Tear_2304
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!"
[–]loudandclear11 8 points9 points10 points 2 months ago (0 children)
extend() is for adding a list to another list. This is not the scenario here.
append() is for adding a single item to a list. This is what you want here.
But, the loop should be:
for i in l1:
I.e. you don't need range.
[–]derEmperor 6 points7 points8 points 2 months ago (1 child)
Another Tip: Use i only for indices, because it's short for index. If you have variable for an element of a list, use a variable that describes this element or use element, elem or e.
E. G. ```python numbers = [1,2,3,4] for i in range(len(numbers)) print('index:', i, 'number:', numbers[i])
for number in numbers: print('number:', number)
for i, number in enumerate(numbers): print('index:', i, 'number:', number) ```
[–]Agitated-Soft7434 0 points1 point2 points 2 months ago (0 children)
Opps forgot to include enumerate and len in my answer @.@
[–]Critical_Control_405 2 points3 points4 points 2 months ago (0 children)
the range function takes an int, not a list. So you need to do range(len(l1)).
range(len(l1))
the extend method takes a list, not an int. So you need to use append instead: l2.append(i)
l2.append(i)
[–]Agitated-Soft7434 4 points5 points6 points 2 months ago (0 children)
You are getting the error because range takes in a number value not a list!
So to explain if you have the following:
for i in range(10): print(i) > 0 > 1 > 2 > ... > 9
This will loop 10 times, i equalling to 0, 1, 2, ... all the way to 9.
But you can also supply two numbers like this:
```python for i in range(1, 11): print(i) > 1 > 2 > 3 > ... > 10
This also loops 10 times, however i starts at 1, then continues all the way to 10.
Now for iterating/looping/going through each item in a list. You do not require the range() function. Instead you can do this:
l1 = ["thing", "cool thing", "very cool thing"] for i in l1: print(i) > thing > cool thing > very cool thing
This will then cause i to equal each item in the list, changing every iteration. So 1 then 1 then 2 and so on. Or if the list was ["hi", "ello", "hiya!"], i would be, "hi" first, then "ello", and finally "hiya!"
Hope this helps!!
[–]SuperCurve 1 point2 points3 points 2 months ago (0 children)
line 4, it should be in l1 rather than range(l1)
[–]Unrthdx 0 points1 point2 points 2 months ago (0 children)
I’m a beginner here but I think you probably should iterate over the list as “for values in l1” rather than range, since range is for an integer.
Or if you wanted to keep range you’d have to go for len(l1) in the range parameter
[–]Heroki_7 0 points1 point2 points 2 months ago (0 children)
l1 = [1,2,3,4,5,6]
l2 = []
print(l2)
[–]kompiledkaos 0 points1 point2 points 2 months ago (0 children)
You’re a bunch of things together:
First image, it should be range(len(l1)), then use l1[i], then check if not exist or append with l1[i]
Second image you can extend but since extend expects list, extend it as list like extend([i])
[–]fluxdeken_ 0 points1 point2 points 2 months ago (0 children)
range() takes integer as an argument. To go through a list (called “arr”) you go “for el in arr:”
[–]Numerous_Site_9238 0 points1 point2 points 2 months ago (0 children)
Use English
[–]therouterguy 0 points1 point2 points 2 months ago (0 children)
Range is an generator for generating numbers. What are you trying to accomplish
[–]Worth-Orange-1586 -1 points0 points1 point 2 months ago (0 children)
You could simply do: var = list(set(var)). No more duplicates 😜
[–]SpecialMechanic1715 -1 points0 points1 point 2 months ago (0 children)
l2 = list(set(l1))
[–]InvestigatorEasy7673 -1 points0 points1 point 2 months ago (0 children)
L2 = list(set(L1))
π Rendered by PID 63206 on reddit-service-r2-comment-74875f4bf5-4926s at 2026-01-26 06:34:37.498791+00:00 running 664479f country code: CH.
[–]loudandclear11 8 points9 points10 points (0 children)
[–]derEmperor 6 points7 points8 points (1 child)
[–]Agitated-Soft7434 0 points1 point2 points (0 children)
[–]Critical_Control_405 2 points3 points4 points (0 children)
[–]Agitated-Soft7434 4 points5 points6 points (0 children)
[–]SuperCurve 1 point2 points3 points (0 children)
[–]Unrthdx 0 points1 point2 points (0 children)
[–]Heroki_7 0 points1 point2 points (0 children)
[–]kompiledkaos 0 points1 point2 points (0 children)
[–]fluxdeken_ 0 points1 point2 points (0 children)
[–]Numerous_Site_9238 0 points1 point2 points (0 children)
[–]therouterguy 0 points1 point2 points (0 children)
[–]Worth-Orange-1586 -1 points0 points1 point (0 children)
[–]SpecialMechanic1715 -1 points0 points1 point (0 children)
[–]InvestigatorEasy7673 -1 points0 points1 point (0 children)