Coder Social home page Coder Social logo

ds-skills-lists-str-iter-practice-atlanta-ds-100918's Introduction

Here's a simple list:

cats = ['Maine Coon', 'Tabby', 'Siamese', 'Garfield', 'Sylvester']
cats
['Maine Coon', 'Tabby', 'Siamese', 'Garfield', 'Sylvester']

Iterate through the list and print each cat.

# Your code here

Create a new list cat_jrs by appending ‘Jr.’ to each of the cats names.

# Your code here

Sort the list in alphabetical order.

# Your code here

Sort the list in reverse alphabetical order

# Your code here

Look up a new string or list method and explain how it works.

# Your code here

Extension: Sort the list by the 3rd letter of each name.

Hint: look at the docstring's optional parameter, key=.
You can then define a special function called a lambda function on the fly like this:
lambda thing: thing*-1 or lambda x: operation(x)

Like a for loop you can create any variable name after calling lambda.
After calling lambda and a variable name, you then always use a colon :.
To the right of the colon is whatever you want your function to do with your variable.

More completely:

numbers = [5,3,7,82, 17]
numbers.sort()
numbers
[3, 5, 7, 17, 82]
numbers.sort(key=lambda x: x*-1) #Effectively sorts in descending order by taking the inverse
numbers
[82, 17, 7, 5, 3]
numbers.sort(key=lambda num: abs(11-num)) #Try to explain what this does.
numbers
[7, 17, 5, 3, 82]
# Your code here

ds-skills-lists-str-iter-practice-atlanta-ds-100918's People

Contributors

mathymitchell avatar

Watchers

 avatar James Cloos avatar Kevin McAlear avatar  avatar Victoria Thevenot avatar Belinda Black avatar  avatar Joe Cardarelli avatar Sam Birk avatar Sara Tibbetts avatar The Learn Team avatar Sophie DeBenedetto avatar  avatar Jaichitra (JC) Balakrishnan avatar Antoin avatar Alex Griffith avatar  avatar Amanda D'Avria avatar  avatar A. Perez avatar Nicole Kroese  avatar  avatar Lore Dirick avatar Nicolas Marcora avatar Lisa Jiang avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.