-2

I don't know how to convert this loop in C to Python. Thanks in advance

I tried to convert

for(i=start, i<=end, i++)
   printf(ids[i])

to:

for x in range(start, end, ids):
   print(x)

But range requires integer values and ids is a list of strings.

I tried casting ids as integers but it says

"ValueError: invalid literal for int()"

I need the values in ids to stay as characters because there are some letters in it.

mischva11
  • 2,535
  • 3
  • 15
  • 31
asor
  • 1
  • `for x in range(start, stop+1, 1): print(ids[x])` this article may be helpful: https://www.w3schools.com/python/ref_func_range.asp – Masoud Jul 02 '19 at 22:54

2 Answers2

1
for id in ids:
    print(id)

will print all ids in the list, you can always set a break statement if you don't want all of them

for id in ids:
    if count > start:
        print(id)

    count += 1

    if count >= end:
        break
LordPotato
  • 53
  • 6
0

If you just want to print the strings

for id in ids:
    print(id)

If you need access to the index

for i in range(len(ids)):
    print(ids[i])

If you need access to the index and only want to loop until end (if 'end' is an integer)

for i in range(end):
    print(ids[i])
Kevin Welch
  • 1,300
  • 1
  • 8
  • 16