Bottom Page

• 1 Vote(s) - 4 Average
• 1
• 2
• 3
• 4
• 5
 Making indices and rearrranging list reidybwoykeon Unladen Swallow Posts: 2 Threads: 1 Joined: May 2017 Reputation: 0 Likes received: 0 #1 May-18-2017, 10:26 AM Good day, I'm fairly new to Python. I have generated a list and want to rearrange it. I want to know what's the best way to go about doing that — should I use indices or a numpy function? This is a portion of my 24 by 24 grid that contains 576 entries.  ['-19.2740144', '-17.9460128', '-18.8874128', '-22.9789464', '-27.8428464'] This is the data set with only 5 entries.  1. Is this the right format to manipulate the numbers? Should I remove the quotation marks using 'strip'? 2. I want to keep the first entry, then reverse the order of the indices, so instead of having 1, 2, 3, 4, 5, I would have 1, 5, 4, 3, 2. For a set of 24 numbers in the list.  3. There's 24 sets of 24. I want to perform strategy 2, then conduct the same procedure on the global list of 576, which means after rearranging I would have the first set of 24, then the 24th set, 23rd set and so on.  These are some of the things I've tried ``` F=open('tranform.txt','r+') for line in F       for index in xrange(23,0,1):            print index *** An example I saw that could be worth using — Would I have to modify definition of the sorted? *** def get_list_indices(ls):     indices = {}     for n, i in enumerate(ls):         try:             indices[i].append(n)         except KeyError:             indices[i] = [n]     return [i[1] for i in sorted(indices.items(), reverse=True)] #test_list = [4, 1, 4, 8, 5, 13, 2, 4, 3, 7, 14, 4, 4, 9, 12, 1, 6, 14, 10, 8, 6, 4, 11, 1, 2, 11, 3, 9] #print(get_list_indices(list)) ```Thanks for any help! « Next Oldest | Next Newest »

Top Page

 Messages In This Thread Making indices and rearrranging list - by reidybwoykeon - May-18-2017, 10:26 AM RE: Making indices and rearrranging list - by buran - May-18-2017, 01:52 PM RE: Making indices and rearrranging list - by reidybwoykeon - May-18-2017, 06:57 PM

 Possibly Related Threads... Thread Author Replies Views Last Post TypeError: list indices must be integers or slices, not str TheDovah7 4 8,494 Mar-06-2018, 03:00 PM Last Post: TheDovah7 Making a list for positive vs negative reviews based on rating fancy_panther 1 1,363 Mar-22-2017, 11:30 PM Last Post: zivoni

Forum Jump:

Users browsing this thread: 1 Guest(s)