list.split not creating a properly functioning list

11 views
Skip to first unread message

Harlan Gilbert

unread,
Jan 26, 2024, 3:13:39 PMJan 26
to Glowscript Users
In this program
a = "Billy, Zac"
a = a.split(", ")

i = a.index("Zac")
a.remove("Zac")
i = a.index("Zac")

Both the index and remove functions throw an error:

TypeError: a.index is not a function

TypeError: a.remove is not a function


If I define
a = ["Billy", "Zac"]

Harlan Gilbert

unread,
Jan 26, 2024, 3:15:03 PMJan 26
to glowscri...@googlegroups.com
Sorry, that got cut off:

If I instead define
a = ["Billy", "Zac"]              #This now works.  The problem is with the split function.



--

---
You received this message because you are subscribed to the Google Groups "Glowscript Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to glowscript-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/glowscript-users/3b35bb39-c783-4876-af6c-47d53cd70bd6n%40googlegroups.com.

Bruce Sherwood

unread,
Jan 26, 2024, 5:33:56 PMJan 26
to Glowscript Users
Thanks for the report. It's odd, since this works properly:

a = "Billy, Zac"
print(a)

a = a.split(", ")
print(a)
print(a[0])
print(a[1])

Here is the output:

Billy, Zac
['Billy', 'Zac']
Billy
Zac

And this works properly:

a = ['Billy', 'Zac']

i = a.index("Zac")
print(i)
a.remove("Zac")
print(a)

i = a.index("Zac")
print(i)
Reply all
Reply to author
Forward
0 new messages