Skip to content

Instantly share code, notes, and snippets.

@arehmandev
Last active March 23, 2022 07:53
Show Gist options
  • Save arehmandev/cd9b368d1447b98527636eba3ad563b2 to your computer and use it in GitHub Desktop.
Save arehmandev/cd9b368d1447b98527636eba3ad563b2 to your computer and use it in GitHub Desktop.
package main
import "fmt"
func main() {
intslice := [][]int{[]int{1}, []int{2}}
// Grow
for index, value := range intslice {
value = append(value, 0)
intslice[index] = value
}
insertion := []int{}
for index := 0; index < len(intslice)+1; index++ {
insertion = append(insertion, 0)
}
intslice = append(intslice, insertion)
fmt.Println(intslice)
// Shrink
for index, value := range intslice {
if len(value) == 0 {
fmt.Println("Cant shrink below 0")
continue
}
value = value[:len(value)-1]
intslice[index] = value
if index == len(intslice)-1 {
intslice = intslice[:len(intslice)-1]
}
}
fmt.Println(intslice)
}
# grows the list by list[len(list[n])+1][len(list[n][n])+1]
pythonlist = [[1], [2]]
for index, i in enumerate(pythonlist):
pythonlist[index].append(0)
pythonlist.append([])
for i in range(len(pythonlist)):
pythonlist[-1].append(0)
# Shrink
print(pythonlist)
# shrinks the list by list[len(list[n])-1][len(list[n][n])-1]
for index, i in enumerate(pythonlist):
pythonlist[index].pop()
pythonlist.pop()
print(pythonlist)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment