0% found this document useful (0 votes)
604 views

Advanced Topics

This document provides definitions and programming exercises on advanced Python topics including tuples, lambdas, list comprehensions, and bitwise operations. It includes 4 exercises: 1) Write a function to remove duplicate elements from a list using for/else, 2) Create a list of squares up to 10 using list comprehension, 3) Write a function to extract numbers from a string into a list using list comprehension, and 4) Write a function to check if a string is a palindrome by checking if it is the same forward and backward after removing punctuation and numbers.

Uploaded by

api-291204383
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as XLSX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
604 views

Advanced Topics

This document provides definitions and programming exercises on advanced Python topics including tuples, lambdas, list comprehensions, and bitwise operations. It includes 4 exercises: 1) Write a function to remove duplicate elements from a list using for/else, 2) Create a list of squares up to 10 using list comprehension, 3) Write a function to extract numbers from a string into a list using list comprehension, and 4) Write a function to check if a string is a palindrome by checking if it is the same forward and backward after removing punctuation and numbers.

Uploaded by

api-291204383
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as XLSX, PDF, TXT or read online on Scribd
You are on page 1/ 1

VOCABULARY

LESSON: ADVANCED TOPICS


PROGRAMMING EXERCISES
(Requires IDLE 2.7.10)

Tuples - tuples - immutable (unchangeable) list


Lambda - anonymous function. Allows you to pass functions around
just as if they were variables or values
Lambdas vs Functions - Lambdas are useful when you need a quick
function to do some work for you whereas functions are great for reuse

#1: Remove Duplicates


Write a function remove_duplicates that takes in a list and removes elements of the
list that are the same using for/else. For example: remove_duplicates([1,1,2,2])
should return [1,2].

#2 List of Squares
Create a list of squares up to 10 using list comprehension and print the results. The
List comprehension- List comprehensions are a powerful way to
results should display [0, 1, 4, 9, 16, 25, 36, 49, 64, 81]
generate lists using the for/in and if keywords. For example, evens_to_50
= [i for i in range(51) if i % 2 == 0]
#3: Extract Numbers from String
Write a function called extract that takes a string as a parameter and returns a list
Bits - a series of zeros and ones which represent numbers in
with all numbers extracted from the string using a list comprehension. For example,
computers.
extract("Hello 12345 World") should return ['1', '2', '3', '4', '5']
Bitwise operations - operations that directly manipulate bits.

PROGRAMMING CHALLENGE # 6
(Prerequisite: Completed Advanced Topics)
Palindrome
Using the Python language, have the function Palindrome(str) take the str
parameter being passed and return the string true if the parameter is a
palindrome, (the string is the same forward as it is backward) otherwise
return the string false. For example: "racecar" is also "racecar"
backwards. Punctuation and numbers will not be part of the string.
def Palindrome(sen):
# code goes here
return
# keep this function call here
print Palindrome(raw_input("Enter a Word ")
Examples of Output:
Input = "never odd or even" Output = "true"
Input = "eye" Output = "true"

You might also like