Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
how to rearrange text
#1
hi,

i am reading a cvs which has column in which there is text written like,
new launch,ready to move,under construction
ready to move,under construction
ready to move,new launch,under construction

i want an order to be set for all . like below:
new launch, under construction, ready to move wherever these three elements are present.

and where these three elements are not present , then order should be :
under construction, new launch

how can i achieve this:

below is my code:
possession = row[7].replace("R","ready to move").replace("N","new launch").replace("UC","under construction")
        if "new launch" in possession:
            print(possession, ">>>", possession.index("new launch"))### dont know how to do it
Reply
#2
Have a sorted (alphabetically) version of the (three item) output line, and an ordered version of the output line.

Loop through the lines converting them to lists. Sort the line. If it's the sorted output line, output the ordered line. Otherwise, output the two-item line.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How can I rearrange df as the nodes index in pytorch geometric manner? uqlsmey 0 510 Jul-31-2023, 11:28 AM
Last Post: uqlsmey
  Rearrange Columns in a CSV File rjj920 1 5,573 May-09-2020, 03:26 PM
Last Post: DPaul

Forum Jump:

User Panel Messages

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