Code Yarns ‍👨‍💻
Tech BlogPersonal Blog

Python: Splicing a List

📅 2009-Oct-01 ⬩ ✍️ Ashwin Nanjappa ⬩ 🏷️ lists, python, splicing ⬩ 📚 Archive

Splicing a list in Python means extracting a subsequence from a list

aList = [5, 6, 7, 8, 9]
aList[2:4] # [7, 8] Yes, end index is one more than the end
aList[:4]  # [5, 6, 7, 8]
aList[2:]  # [7, 8, 9]
aList[:]   # Complete list