Python Forum
Copying the order of another list with identical values
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Copying the order of another list with identical values
#8
This seems to do the job:

hub_sn = [10001, 10002, 10003, 10004, 10005]
hub_sn_avail = [(10003, 'Online'), (10004, 'Offline'), (10002, 'Online'), (10001, 'Offline'), (10005, 'Online')]
mylist = [(k, j[1]) for k in hub_sn for j in hub_sn_avail if k in j]
Output:
mylist [(10001, 'Offline'), (10002, 'Online'), (10003, 'Online'), (10004, 'Offline'), (10005, 'Online')]
There may be disadvantages due to the double loop for very long lists.
Reply


Messages In This Thread
RE: Copying the order of another list with identical values - by Pedroski55 - Nov-29-2023, 09:17 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Search Excel File with a list of values huzzug 4 1,306 Nov-03-2023, 05:35 PM
Last Post: huzzug
  Copy List Not Copying BAbdulBaki 3 674 Aug-19-2023, 02:03 AM
Last Post: perfringo
  Comparing List values to get indexes Edward_ 7 1,238 Jun-09-2023, 04:57 PM
Last Post: deanhystad
  Why do I have to repeat items in list slices in order to make this work? Pythonica 7 1,399 May-22-2023, 10:39 PM
Last Post: ICanIBB
  Adding values with reduce() function from the list of tuples kinimod 10 2,768 Jan-24-2023, 08:22 AM
Last Post: perfringo
  user input values into list of lists tauros73 3 1,104 Dec-29-2022, 05:54 PM
Last Post: deanhystad
  AttributeError: 'list' object has no attribute 'values' ilknurg 4 15,155 Jan-19-2022, 08:33 AM
Last Post: menator01
  Need to parse a list of boolean columns inside a list and return true values Python84 4 2,152 Jan-09-2022, 02:39 AM
Last Post: Python84
  List of dataframe values beginning with x,y or z glidecode 3 1,981 Nov-08-2021, 10:16 PM
Last Post: glidecode
  How to pass list of values to a API request URL chetansaip99 0 3,559 Sep-28-2021, 07:37 AM
Last Post: chetansaip99

Forum Jump:

User Panel Messages

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