Skip to content

Instantly share code, notes, and snippets.

@chris-martin
Last active December 15, 2015 01:59
Show Gist options
  • Save chris-martin/5184209 to your computer and use it in GitHub Desktop.
Save chris-martin/5184209 to your computer and use it in GitHub Desktop.
"Python’s Pragmatism: This example showcases the ease in which arrays can be created and manipulated. Define a list, print an item in that list, or replace an item with simple methods." - from http://preview.python.org/ 2013-03-17
>>> l = ['spam', 'ham', 314, 23]
>>> l
['spam', 'ham', 314, 23]
>>> l[0]
'spam'
>>> l[0] = 'monkey'
>>> l
['monkey', 'ham', 314, 23]
scala> val l = List("spam", "ham", 314, 23)
l: List[Any] = List(spam, ham, 314, 23)
scala> l(0)
res1: Any = spam
scala> l.updated(0, "monkey")
res2: List[Any] = List(monkey, ham, 314, 23)
scala> val l = collection.mutable.ArrayBuffer("spam", "ham", 314, 23)
l: scala.collection.mutable.ArrayBuffer[Any] = ArrayBuffer(spam, ham, 314, 23)
scala> l(0)
res1: Any = spam
scala> l(0) = "monkey"
scala> l
res2: scala.collection.mutable.ArrayBuffer[Any] = ArrayBuffer(monkey, ham, 314, 23)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment