Python Forum

Full Version: how to rearrange text
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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
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.