Python Forum
Adding elements to a list by number
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Adding elements to a list by number
#1
How do I add elements to a list by number?
If I wanted to add elements that are grouped in three's from a list to three other lists, how would I do it?

For example if the numbers under was in a list called raw:
23
45
24
09
18
23
65
78
61
How would I get the first three, the middle three, and then the last into three different lists?
Reply
#2
you can do this by using just Standard library, but if not restricted to install and use third party libraries, look at more-itertools package
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#3
What have you thought about? You don't necessarily need any libraries to do this, but can do it with the basic operations that you can perform on lists.
Reply
#4
(Feb-07-2020, 02:10 PM)ndc85430 Wrote: What have you thought about? You don't necessarily need any libraries to do this, but can do it with the basic operations that you can perform on lists.
What basic operations?
Reply
#5
Do you know how to access items in a list by index? That's basically all you need.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  unable to remove all elements from list based on a condition sg_python 3 377 Jan-27-2024, 04:03 PM
Last Post: deanhystad
Question mypy unable to analyse types of tuple elements in a list comprehension tomciodev 1 427 Oct-17-2023, 09:46 AM
Last Post: tomciodev
  Delete strings from a list to create a new only number list Dvdscot 8 1,466 May-01-2023, 09:06 PM
Last Post: deanhystad
  find random numbers that are = to the first 2 number of a list. Frankduc 23 3,049 Apr-05-2023, 07:36 PM
Last Post: Frankduc
  Checking if a string contains all or any elements of a list k1llcod3 1 1,023 Jan-29-2023, 04:34 AM
Last Post: deanhystad
  Adding values with reduce() function from the list of tuples kinimod 10 2,518 Jan-24-2023, 08:22 AM
Last Post: perfringo
  How to change the datatype of list elements? mHosseinDS86 9 1,912 Aug-24-2022, 05:26 PM
Last Post: deanhystad
  TypeError: float() argument must be a string or a number, not 'list' Anldra12 2 4,768 Jul-01-2022, 01:23 PM
Last Post: deanhystad
  ValueError: Length mismatch: Expected axis has 8 elements, new values have 1 elements ilknurg 1 5,014 May-17-2022, 11:38 AM
Last Post: Larz60+
  Split a number to list and list sum must be number sunny9495 5 2,200 Apr-28-2022, 09:32 AM
Last Post: Dexty

Forum Jump:

User Panel Messages

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