Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@balu
Created February 2, 2021 06:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save balu/6d3ee19970c3a18119920617e6320335 to your computer and use it in GitHub Desktop.
Save balu/6d3ee19970c3a18119920617e6320335 to your computer and use it in GitHub Desktop.

Introduction

Use the following guidelines to manipulate lists.

  1. The output list is initially empty or some fixed sequence.
  2. Use for x in xs: to process each element of the input sequence xs in turn.
  3. Process the element x appropriately.
  4. Append the element corresponding to x into the output list.
  5. Once you've finished processing all elements, return the output list.

Questions

  1. Write a function length that takes a list and returns its length.
  2. Write a function max that takes a list and returns the largest number in the list.
  3. Write a function first_negative that takes a list and returns the first negative number in the list. If all numbers are non-negative, return 0.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment