0
I'm having trouble using list functions. My goal is to iterate 0_9 counted by 2s evenly, and 9_15 by 2s odds.
Ive tried range and set, plus min max. Im not understanding the syntax.
26 odpowiedzi
+ 1
Jay Matthews [*range(9, 16, 2)] would be a faster alternative though.
+ 1
* is an "all arguement" factor rite?
+ 1
Aaron Yup, the asterisk in my code 'breaks down the iterator' by passing all the values retuned by it as separate entities to the list, one by one. I won't call it 'arguments', though.
+ 1
So it individualizes the factors
+ 1
Do i use brackets for functions regarding list, and, if im calling a functiin am I to use the same parameter identifiers as the data set.
+ 1
a_list = [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]
a_list = a_list.range(9,16,2)
print(a_list)
First the asterix is called invalid syntax, then I get object list has no attribute range.
Now I'm trying to just count the list by twos before I do the original objective.
What am I doing wrong?
+ 1
Slicen dicen it is then
+ 1
Thats my prob. Im using commas not colons
+ 1
It calls colons synerr
+ 1
a=range(0,10,2)
b=list(a)
c=range(9,16,2)
d=list(c)
print(b)
print(d)
[0,2,4,6,8]
[9,11,13,15]
Print(b+c) == can only concatenate list (not "range") to list.
+ 1
Print(b.append(d))==none
+ 1
Im trying to count evens by twos 0-10 and odds by twos 9_15 but I want to do it in one list.
+ 1
So what ive learned is range is a data type and I cant convert rang in the os to a list because list conversion only applies to tuples and strings, which is why I get back none when i run even.extend(odd)
Which should concatenate the 'lists'.
And an error when i insert odd at14,15,or16. If Im wrong let me know
+ 1
Aaron Now I see what you're really intending for. Here's a possible solution:
merged_list = list(x for x in list if not x & 1) + list(x for x in list if x & 1)
# Hope this helps
# Happy coding!
0
Ive thought about seperating the list and putting it back together but I dont get that either. I think i dont understand how to assign the function
0
How do I range.
List.range(0,10,2) ?
0
K thanx
0
Aaron Could you please elaborate on your most recent question?
0
Aaron The list class has no such method called 'range'. You may go with slicing instead.
0
[9:16:2] - Doesn't this work?