-1

I have a string that is a repeating decimal. The string value may or may not have values to the left of the decimal: ".33333333" or "1.6666666666" or "12125.464646464646".

I want to iterate through the string starting directly after the decimal. Is there a way to start a for loop directly to the right of the decimal?

Ideally, you would not cut or split the string in advance. The question is more geared towards starting a for loop at a specific point given a specific character versus looping through a full string that has been cut.

.333333 would start at 3

1.66666 would start at 6

12125.464646 would start at 4

Mazzone
  • 401
  • 1
  • 6
  • 21

3 Answers3

0

There are many ways to do this. One possible way is to use find(),

inp = "12125.464646464646"
for x in xrange(inp.find('.')+1, len(inp)):
  print inp[x],

Also you can try,

inp = "12125.464646464646"
for a in inp[inp.find('.')+1:]:
Fallen
  • 4,435
  • 2
  • 26
  • 46
0

Try with split,

a="12125.464646464646"
for i in a.split('.')[-1]:
     print i
Rahul K P
  • 15,740
  • 4
  • 35
  • 52
0

Hi try this simplified code

 a="12125.464646464646"
 print [i for i in a.split('.')[1]]
 #output:- ['4', '6', '4', '6', '4', '6', '4', '6', '4', '6', '4', '6']
Hilar AK
  • 1,655
  • 13
  • 25