Python Forum
Take first Elements of sublists
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Take first Elements of sublists
#1
This is my list:

list_of_lists = [[1, 2], [3, 4]]
I want to group of elements of sublists:

list_of_lists = [[1, 2], [3, 4]]
n=[]
for list in list_of_lists:
   n.append(list[0]) #I am taking 1 and 3
   n.append(list[1]) # I am taking 2 and 4 
But sometimes I can have 100 elements too so I want to do it dynamically instead of writing [0],[1]

How can I do that?
Reply


Messages In This Thread
Take first Elements of sublists - by quest - Apr-26-2021, 11:15 AM
RE: Take first Elements of sublists - by perfringo - Apr-26-2021, 11:31 AM
RE: Take first Elements of sublists - by buran - Apr-26-2021, 11:32 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  ValueError: Length mismatch: Expected axis has 8 elements, new values have 1 elements ilknurg 1 5,116 May-17-2022, 11:38 AM
Last Post: Larz60+
  List of lists - merge sublists with common elements medatib531 1 3,396 May-09-2021, 07:49 AM
Last Post: Gribouillis
  Sorting Elements via parameters pointing to those elements. rpalmer 3 2,586 Feb-10-2021, 04:53 PM
Last Post: rpalmer
  Flatten list sublists chesschaser 8 2,908 Jul-07-2020, 11:38 AM
Last Post: chesschaser
  Converting list elements and sublists from int to str iMuny 5 4,555 Mar-10-2019, 09:05 PM
Last Post: iMuny

Forum Jump:

User Panel Messages

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