python hw

in python file. not text file. 

Save Time On Research and Writing
Hire a Pro to Write You a 100% Plagiarism-Free Paper.
Get My Paper

 

only in case of you can’t upload/use .py file, you can give it to me in text file

ISTA

1

Save Time On Research and Writing
Hire a Pro to Write You a 100% Plagiarism-Free Paper.
Get My Paper

30: Homework 8

1 Practice with strings and lists

The first two problems are from checkio.org; if you want, you can create an account there and
solve them on the website, where there are some additional hints (and less fluent English).

1. (

2

pt.) Given a string that is a sentence, write a function to remove all of the extra spaces
between words; words should have only one space between them

Example:

>>> print one_space(“Big space here”)

Big space here

2. (2 pt.) Given a list of integers, write a function to return a list consisting of only non-unique
elements. That is, return only elements that appear more than once in the list. You may
want to build up a new list of these elements using “append”

Example:

>>> non_unique([1,3,2,5,3,1,4])

[1,3,3,1]

3. (3 pt.) Make a program to take all the capitalized words out of a text file, using a for loop. It
should take the text files name as input, and output the modified text to a new text file. Run
the program on the “20k excerpt.txt” example file (posted on D2L) and turn in the results.

4. (3 pt.) Make a copy of your program, and rewrite it to use a list comprehension to remove
the capitalized words.

5. (5 pt.) Given a list of items, print them out in two equal-length columns (plus or minus one
item). You’ll want to use your string formatting methods. You may want to split the list of
items in two. You’ll also need to consider how to determine the width of the columns. All of
the items in the second column should be aligned with each other.

When it’s ready, try your function out on these lists:

>>> shorts = [’cat’, ’dog’, ’bear’, ’fish’, ’pig’, ’cow’, ’ant’, ’bat’]

>>> longs = [’kangaroo’, ’echidna’, ’platypus’, ’wallaby’, ’koala’]

1

The output should be something like:

>>> print_columns(shorts)

cat pig

dog cow

bear ant

fish bat

>>> print_columns(longs)

kangaroo wallaby

echidna koala

platypus

2

  • What to turn in
  • Submit your hw08.py script to the Homework 8 Dropbox folder in D2L. Also submit your modified
    20k excerpt.txt file.

    Total Points: 15 points possible
    Extra Credit: 0 points possible

    2

    • Practice with strings and lists (Homework 8)
    • Working with data files (Homework 9)
    • What to turn in

    Order your essay today and save 25% with the discount code: GREEN

    Order a unique copy of this paper

    600 words
    We'll send you the first draft for approval by September 11, 2018 at 10:52 AM
    Total price:
    $26
    Top Academic Writers Ready to Help
    with Your Research Proposal

    Order your essay today and save 25% with the discount code GREEN