List examples in Python, JavaScript, and Pseudocode.

fruits = ["apple", "grape", "strawberry"]
print (fruits)
const fruits = ["apple", "grape", "strawberry"];
fruits  [apple, grape, strawberry]

Terms

  • Index: a term used to sort data in order to reference to an element in a list
  • Elements: the values in the list assigned to an index
fruits = ["apple", "grape", "strawberry"]
index = 1

print (fruits[index])
grape
words = ["alfa", "bravo", "charlie", "delta", "echo", "foxtrot", "golf", "hotel", "india", "juliett", "kilo",
"lima", "mike", "november", "oscar", "papa", "quebec", "romeo", "sierra", "tango", "uniform", "victor", "whiskey", "xray", "yankee", "zulu"]

letters = ["a", "b", "c", "d", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"]



inp = input().lower()

Methods in Lists

Method Definition Example
append() adds element to the end of the list fruits.append("watermelon")
index() returns the index of the first element with the specified value fruits.index("apple")
insert() adds element at given position fruits.insert(1, "watermelon")
remove() removes the first item with the specified value fruits.remove("strawberry")
reverse() reverses the list order fruits.reverse()
sort() sorts the list fruits.sort()
count() returns the amount of elements with the specified value fruits.count("apple")
copy() returns a copy of the list fruits.copy()
clear() removes the elements from the list fruits.clear()
sports = ["football", "soccer", "baseball", "basketball"]
sports[1] = "hockey"
# change the value "soccer" to "hockey"
print (sports)
['football', 'hockey', 'baseball', 'basketball']
sports = ["football", "soccer", "baseball", "basketball"]

# add "golf" as the 3rd element in the list
print (sports)

Try this

  • Determine the output of the code segment

pc