Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Need help
#10
(Nov-27-2020, 10:18 AM)Radez Wrote: I tried a few times to use your code but it still uses the same amount of steps to change text to numbers as my old one did.
for i in range(n):
    t[i]=int(t[i]

The number of steps is the same because you have to process every number entered, but... lookup of items at specific indices takes time (you make two lookups for every iteration) and this code is not idiomatic Python. It is something you write in Java. In Python you can iterate directly over items:

for item in n:
    # do something with item
There is list comprehension (example provided earlier by snippsat) for creating new list from iterable. As snippsat pointed out, you can do: 'split user input on whitespaces and convert every item in resulting list to integer'. This is efficient and idiomatic Python.
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply


Messages In This Thread
Need help - by Radez - Nov-26-2020, 03:50 PM
RE: Need help - by snippsat - Nov-26-2020, 04:51 PM
RE: Need help - by deanhystad - Nov-26-2020, 06:29 PM
RE: Need help - by Radez - Nov-26-2020, 08:41 PM
RE: Need help - by Radez - Nov-26-2020, 08:43 PM
RE: Need help - by deanhystad - Nov-26-2020, 09:50 PM
RE: Need help - by snippsat - Nov-27-2020, 03:19 AM
RE: Need help - by perfringo - Nov-27-2020, 06:54 AM
RE: Need help - by Radez - Nov-27-2020, 10:18 AM
RE: Need help - by perfringo - Nov-27-2020, 11:19 AM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020