+ 1
Python making infinite range and list
How we can make an infinite range or list and put numbers from zero or -inf to +inf ?
7 Respostas
+ 6
mojaka ,
since it is not clearly defind what the input range or output should be, it would be very helpful if you do an attempt and link it here.
> do you need to get one or more random values out of a range of values?
> do you need to get sequential values in a defined range?
+ 6
mojaka ,
(1) the code you presented is working! an other way would be to use the string method .isdigit():
... loop with variable `c`
if c.isdigit():
...
doing so, we can avoid the try... except... code block.
(2) i did not get your last question, can you explain what you need? what is the core task of your exercise?
+ 4
I'm pretty sure it would lead to time-out....
+ 3
But an infinite list has no end, so your program would forever be compiling to create the list. You could make a very large list, I'm not sure what limit there is (I'm sure the information is online 😉).
Here are some codes with lists in python. See what you can learn from them.
https://code.sololearn.com/WEssz6rgIH90/?ref=app
https://code.sololearn.com/c8WZ57m6I2nl/?ref=app
https://code.sololearn.com/cOfs67AUdIzi/?ref=app
https://code.sololearn.com/c3a25A11a23A/?ref=app
https://code.sololearn.com/cqZHUF0DcYj2/?ref=app
+ 2
Loop the string and check if the character is a number.
for c in string:
try:
int(c)
print("string has a number")
except:
continue
+ 1
Lothar
Can you tell the way that we can do both of it ?
0
Is there any method or somthing that it means all numbers i want to make if codition and say if certain string had number on it do somthing