Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Split and sort input file
#1
Hi there, I need help with the following code. I am trying to sort the list but only getting the last sentence of the file sorted. What am I doing wrong?
fname = input("Enter file name: ")
fh = open(fname)
lst = list(fh)
for line in lst:
    line = line.rstrip()
    print line
    y = line.split()

k = y.sort()
print y
Reply


Messages In This Thread
Split and sort input file - by aawaleh - Apr-08-2020, 10:19 PM
RE: Split and sort input file - by TomToad - Apr-09-2020, 08:28 AM
RE: Split and sort input file - by aawaleh - Apr-09-2020, 08:27 PM
RE: Split and sort input file - by aawaleh - Apr-10-2020, 06:54 PM
RE: Split and sort input file - by aawaleh - Apr-10-2020, 09:59 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
Sad How to split a String from Text Input into 40 char chunks? lastyle 7 1,144 Aug-01-2023, 09:36 AM
Last Post: Pedroski55
  How to "tee" (=split) output to screen and into file? pstein 6 1,406 Jun-24-2023, 08:00 AM
Last Post: Gribouillis
  Split pdf in pypdf based upon file regex standenman 1 2,100 Feb-03-2023, 12:01 PM
Last Post: SpongeB0B
Question Take user input and split files using 7z in python askfriends 2 1,106 Dec-11-2022, 07:39 PM
Last Post: snippsat
  How to sort .csv file test log which item first fail and paint color SamLiu 24 4,925 Sep-03-2022, 07:32 AM
Last Post: Pedroski55
  How to split the input taken from user into a single character? mHosseinDS86 3 1,184 Aug-17-2022, 12:43 PM
Last Post: Pedroski55
Photo a.sort() == b.sort() all the time 3lnyn0 1 1,325 Apr-19-2022, 06:50 PM
Last Post: Gribouillis
  Reading an Input File DaveG 1 1,258 Mar-27-2022, 02:08 AM
Last Post: deanhystad
  How to split file by same values from column from imported CSV file? Paqqno 5 2,803 Mar-24-2022, 05:25 PM
Last Post: Paqqno
  [split] Results of this program in an excel file eisamabodian 1 1,585 Feb-11-2022, 03:18 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020