python - How to tell if item in list contains certain characters -
I have a script that creates a list of numbers, and I want to remove all the numbers from the list which is full There are no numbers (i.e. anything except zero after the decimal point) However, the dragon creates a list where the whole numbers are also found .0 are placed on the end, and as a result I can tell them differently with numbers than anything else. I can not use the int () function because it applies to all of them and makes them all integers, and then I lose the values that were originally.
Here is my code:
z = 300 mylist = [] while (z> 1): z = z - 1 x = 600851475143 / z mylist. The append (x) print (mylist) [for yy in mylist, if the Y #insert rule shows what's in .0 here]
In the first bit, only 600851475143 in every number Replaces between 300 and 1 in return. I need to filter this list then, to get those people who are whole numbers, I have a filter, but where I need a rule of comment that will tell what the special value is in the list .0 < / P>
Can it be achieved in any way?
You can use divmod () and only "divide" into your list ":
z = 300 mylist = [] while (z> 1): z = z - 1 x, y = divmod (600851475143, z) if y == 0: mylist.append (x) Print (mylist)
Comments
Post a Comment