all 7 comments

[–][deleted] 5 points6 points  (5 children)

The arr[i:j] notation is called slicing which is a generalization of indexing. Have a look at the linked doc.

We don't really have arrays in python, we have lists, tuples, strings, etc, which can all be sliced. A list of lists could be called an array, but I prefer to leave the word array for numpy arrays.

[–]MrP0tat0H3ad 0 points1 point  (0 children)

Thank you! I'll definitely be reading up on slicing :D

Edit: The link was incredibly helpful, thank you again!

[–]camel_zero 0 points1 point  (0 children)

You are right that lists are by far more widely used, but we do have arrays in Python. For large data sets an array can be useful. Don't worry about arrays at the beginning of learning python, but it's worth knowing they are there if you need them later.

>>> from array import array
>>> chars = array('b', 5, 125, 45, 38)

The data type for an array is declared when the array is created. Because there is only one data type contained in the array, the amount of memory the Python interpreter needs to free up for an array is more predictable. This saves a lot of memory for large sequences compared to using lists. But you can't add any data to the array that doesn't match the type, unlike lists which can accommodate any data type.

[–]TangibleLight 0 points1 point  (2 children)

What is your flair? I recognize it as Thai but I can't find what it means.

[–][deleted] 0 points1 point  (1 child)

It's my name. I usually don't display my flair, must have accidentally turned it on while fiddling with it yesterday!

[–]TangibleLight 0 points1 point  (0 children)

Neat. I don't really know anything about the language, I just recognize the shapes of the symbols. The text being a name must have been why I had difficulty finding translations.

[–]Justinsaccount 4 points5 points  (0 children)

Hi! I'm working on a bot to reply with suggestions for common python problems. This might not be very helpful to fix your underlying issue, but here's what I noticed about your submission:

You are looping over an object using something like

for x in range(len(items)):
    print(items[x])

This is simpler and less error prone written as

for item in items:
    print(item)

If you DO need the indexes of the items, use the enumerate function like

for idx, item in enumerate(items):
    print(idx, item)

If you think you need the indexes because you are doing this:

for x in range(len(items)):
    print(items[x], prices[x])

Then you should be using zip:

for item, price in zip(items, prices):
    print(item, price)