Slice Notation with Python

I recently began working in "Grokking Algorithms" by Aditya Y. Bhargava. Just four chapters in, and I have learned so much (and remembered so much from my long-forgotten math classes) that I MUST share the experience with y'all, but that will have to be a later post because: PYTHON. SLICES.

The principles for creating a substring from a string in Python apply to solving the question:

How do I filter my string ONLY to see what I am looking for in this string?

  • One way to do?string manipulation in Python?is by implementing?slice() notation.
  • Slice() notation?is a way to?pull specific items into a smaller string from a larger one.
  • You pull specific items by?setting?the?start point?and?endpoint?for the items you are looking for, then?specifying a pattern using?step.
  • You?specify the location?of the items you are manipulating by?calling?the?start?and?end index.
  • By specifying the start, end, and step, you can isolate items by placing them into a?new string.

By implementing slice() notation, I wrote recursive functions that found the number of items in a list and the max item of a list.?

A Note: the exercises for this chapter are not working with strings but arrays. I found reading?"How to Substring a String in Python"??on FreeCodeCamp very helpful. By starting with strings, I was able to then manipulate arrays with the help of?this Stack Overflow post.

要查看或添加评论,请登录

社区洞察