Question
Python sort list in Python 3 This is a second request as the first request was filled, but it does not meet the objective of
Python sort list in Python 3
This is a second request as the first request was filled, but it does not meet the objective of what I am trying to produce and as well produces a blank output I appreciate the first attempt at helping me with this code, but unfortunately it is not working and does not produce the output that i need.
Using the following input labeled presidents.txt:
Lincoln Abraham 3/4/1861 4/15/1865 Jackson Andrew 3/4/1829 3/4/1837 Johnson Andrew 4/15/1865 3/4/1869 Obama Barack 1/20/2009 incumbant Harrison Benjamin 3/4/1889 3/4/1893 Clinton Bill 1/20/1993 1/20/2001 Coolidge Calvin 8/2/1923 3/4/1929 Arthur Chester A 9/19/1881 3/4/1885 Eisenhower Dwight D 1/20/1953 1/20/1961 Pierce Franklin 3/4/1853 3/4/1857 Roosevelt Franklin D 3/4/1933 4/12/1945 Washington George 4/30/1789 3/4/1797 Bush George H W 1/20/1989 1/20/1993 Bush George W 1/20/2001 1/20/2009 Ford Gerald 8/9/1974 1/20/1977 Cleveland Grover 3/4/1885 3/4/1889 Cleveland Grover 3/4/1893 3/4/1897 Truman Harry S 4/12/1945 1/20/1953 Hoover Herbert 3/4/1929 3/4/1933 Madison James 3/4/1809 3/4/1817 Monroe James 3/4/1817 3/4/1825 Buchanan James 3/4/1857 3/4/1861 Garfield James A 3/4/1881 9/19/1881 Polk James K 3/4/1845 3/4/1849 Carter Jimmy 1/20/1977 1/20/1981 Adams John 3/4/1797 3/4/1801 Tyler John 4/4/1841 3/4/1845 Kennedy John F 1/20/1961 11/22/1963 Adams John Quincy 3/4/1825 3/4/1829 Johnson Lyndon B 11/22/1963 1/20/1969 Van Buren Martin 3/4/1837 3/4/1841 Fillmore Millard 7/9/1850 3/4/1853 Nixon Richard M 1/20/1969 8/9/1974 Reagan Ronald 1/20/1981 1/20/1989 Hayes Rutherford B 3/4/1877 3/4/1881 Roosevelt Theodore 9/14/1901 3/4/1909 Jefferson Thomas 3/4/1801 3/4/1809 Grant Ulysses S 3/4/1869 3/4/1877 Harding Warren G 3/4/1921 8/2/1923 McKinley William 3/4/1897 9/14/1901 Harrison William Henry 3/4/1841 4/4/1841 Taft William Howard 3/4/1909 3/4/1913 Wilson Woodrow 3/4/1913 3/4/1921 Taylor Zachary 3/4/1849 7/9/1850
Each line in this file has four pieces of information, separated by tabs.
Last name \t First name \t Date took office \t Date left office
Lincoln\tAbraham\t3/4/1861\t4/15/1865
The four pieces of information are:
Lincoln
Abraham
3/4/1861
4/15/1865
I need help with a python 3 script that will read from presidents.txt and produce 3 seperate .txt files
The first output file needs to be named same_order.txt, thus far my pseudo code is:
open the input file open the output file for each line in the input file: call function to write out the sentence close the input file close the output file
with an output of:
Abraham Lincoln was president from 3/4/1861 to 4/15/1865. Andrew Jackson was president from 3/4/1829 to 3/4/1837. Andrew Johnson was president from 4/15/1865 to 3/4/1869.
the second output file needs to be named last_name.txt and have an output like this:
John Adams was president from 3/4/1797 to 3/4/1801. John Quincy Adams was president from 3/4/1825 to 3/4/1829. Chester A Arthur was president from 9/19/1881 to 3/4/1885.
In the cases where the last names are the same, the Johnsons, the Adams's, and the Bushes, sort by first name
The third and final output file needs to be named inauguration.txt with an output that looks like this:
George Washington was president from 4/30/1789 to 3/4/1797. John Adams was president from 3/4/1797 to 3/4/1801. Thomas Jefferson was president from 3/4/1801 to 3/4/1809.
for both William Henry Harrison and James A Garfield who served less than one year as president. I should include the month that the president took office as the order of data, not just the year.
I need to mainly keep the data ordered within code, rather than trying to rearrange the input data file
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started