Using a range type variable as an object in a list | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Using a range type variable as an object in a list

For example: list1 = [range(20,30),range(1000,5000)] x = int(input()) for i in list1: if x in i: print (i) I also tried assigning the ranges to variables and variables in the list. (didn't work)

28th Jun 2018, 8:25 PM
David Gedalia Ordman
David Gedalia Ordman - avatar
10 Answers
+ 3
How about this. Two lists for each range in parent list. https://code.sololearn.com/c4roA6kOkI0c
28th Jun 2018, 9:49 PM
John Wells
John Wells - avatar
+ 2
tx guys
28th Jun 2018, 9:56 PM
David Gedalia Ordman
David Gedalia Ordman - avatar
+ 2
It is a subclass of iterable allowing it be used in a for loop created by the range function. Basically, it looks ahead one value so it knows if there is something to return next time. https://thepythonguru.com/JUMP_LINK__&&__python__&&__JUMP_LINK-builtin-functions/range/
21st Apr 2020, 3:34 PM
John Wells
John Wells - avatar
28th Jun 2018, 9:13 PM
Markus Kaleton
Markus Kaleton - avatar
0
Sorta, tx
28th Jun 2018, 9:42 PM
David Gedalia Ordman
David Gedalia Ordman - avatar
0
OMG that's exactly what I thought
28th Jun 2018, 9:51 PM
David Gedalia Ordman
David Gedalia Ordman - avatar
0
LOL
28th Jun 2018, 9:51 PM
David Gedalia Ordman
David Gedalia Ordman - avatar
28th Jun 2018, 9:56 PM
David Gedalia Ordman
David Gedalia Ordman - avatar
0
np. + In the latest code you posted you are missing a closing bracket ]. and you are comparing int to the lists so you need to use that for loop for it like you had originally for i in list1: if x in i:
29th Jun 2018, 4:28 AM
Markus Kaleton
Markus Kaleton - avatar
0
What is "range object" in python?
21st Apr 2020, 5:52 AM
Hari Krishna Sahu
Hari Krishna Sahu - avatar