Advanced Topics
Advanced Topics
#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"