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.

14th Aug 2021, 1:21 AM
Aaron
Aaron - avatar
26 odpowiedzi
+ 1
Jay Matthews [*range(9, 16, 2)] would be a faster alternative though.
14th Aug 2021, 4:56 AM
Calvin Thomas
Calvin Thomas - avatar
+ 1
* is an "all arguement" factor rite?
14th Aug 2021, 5:34 AM
Aaron
Aaron - avatar
+ 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.
14th Aug 2021, 5:36 AM
Calvin Thomas
Calvin Thomas - avatar
+ 1
So it individualizes the factors
14th Aug 2021, 5:38 AM
Aaron
Aaron - avatar
+ 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.
14th Aug 2021, 5:40 AM
Aaron
Aaron - avatar
+ 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?
14th Aug 2021, 5:00 PM
Aaron
Aaron - avatar
+ 1
Slicen dicen it is then
14th Aug 2021, 5:17 PM
Aaron
Aaron - avatar
+ 1
Thats my prob. Im using commas not colons
14th Aug 2021, 5:20 PM
Aaron
Aaron - avatar
+ 1
It calls colons synerr
14th Aug 2021, 5:21 PM
Aaron
Aaron - avatar
+ 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.
14th Aug 2021, 6:29 PM
Aaron
Aaron - avatar
+ 1
Print(b.append(d))==none
14th Aug 2021, 6:30 PM
Aaron
Aaron - avatar
+ 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.
14th Aug 2021, 7:05 PM
Aaron
Aaron - avatar
+ 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
14th Aug 2021, 7:39 PM
Aaron
Aaron - avatar
+ 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!
14th Aug 2021, 8:02 PM
Calvin Thomas
Calvin Thomas - avatar
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
14th Aug 2021, 1:23 AM
Aaron
Aaron - avatar
0
How do I range. List.range(0,10,2) ?
14th Aug 2021, 2:33 AM
Aaron
Aaron - avatar
0
K thanx
14th Aug 2021, 2:38 AM
Aaron
Aaron - avatar
0
Aaron Could you please elaborate on your most recent question?
14th Aug 2021, 5:46 AM
Calvin Thomas
Calvin Thomas - avatar
0
Aaron The list class has no such method called 'range'. You may go with slicing instead.
14th Aug 2021, 5:05 PM
Calvin Thomas
Calvin Thomas - avatar
0
[9:16:2] - Doesn't this work?
14th Aug 2021, 5:19 PM
Calvin Thomas
Calvin Thomas - avatar