Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
count item in list
#8
What do you think should happen when you append a list to a list? Did you think it would make the original list longer? Append (and insert) treat the argument as an object, not an iterable. From the docs:
Quote:list.append(x)
Add an item to the end of the list. Equivalent to a[len(a):] = [x].
You could use extend to add items from a list to an existing list.
Output:
list.extend(iterable) Extend the list by appending all the items from the iterable. Equivalent to a[len(a):] = iterable
And as the extend description from the manual hints, you can do the same thing with slices. You can also concatenate lists using '+'

Lists are important in Python. You need to REALLY understand how they work or it is going to come back to bite you again and again.
Reply


Messages In This Thread
count item in list - by korenron - Jun-30-2021, 01:23 PM
RE: count item in list - by deanhystad - Jun-30-2021, 01:31 PM
RE: count item in list - by korenron - Jun-30-2021, 01:53 PM
RE: count item in list - by deanhystad - Jun-30-2021, 02:04 PM
RE: count item in list - by korenron - Jun-30-2021, 03:22 PM
RE: count item in list - by DeaD_EyE - Jun-30-2021, 03:38 PM
RE: count item in list - by korenron - Jul-01-2021, 08:48 AM
RE: count item in list - by deanhystad - Jul-01-2021, 01:46 PM
RE: count item in list - by naughtyCat - Aug-18-2021, 06:40 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Function to count words in a list up to and including Sam Oldman45 15 6,752 Sep-08-2023, 01:10 PM
Last Post: Pedroski55
  Row Count and coloumn count Yegor123 4 1,375 Oct-18-2022, 03:52 AM
Last Post: Yegor123
  For Word, Count in List (Counts.Items()) new_coder_231013 6 2,669 Jul-21-2022, 02:51 PM
Last Post: new_coder_231013
Question Finding string in list item jesse68 8 1,930 Jun-30-2022, 08:27 AM
Last Post: Gribouillis
  How to get unique entries in a list and the count of occurrence james2009 5 3,026 May-08-2022, 04:34 AM
Last Post: ndc85430
  how to easily create a list of already existing item CompleteNewb 15 3,657 Jan-06-2022, 12:48 AM
Last Post: CompleteNewb
  Remove an item from a list contained in another item in python CompleteNewb 19 5,865 Nov-11-2021, 06:43 AM
Last Post: Gribouillis
  Time.sleep: stop appending item to the list if time is early quest 0 1,894 Apr-13-2021, 11:44 AM
Last Post: quest
  list.count does not appear to function Oldman45 7 3,995 Mar-16-2021, 04:25 PM
Last Post: Oldman45
  How to run a pytest test for each item in a list arielma 0 2,387 Jan-06-2021, 10:40 PM
Last Post: arielma

Forum Jump:

User Panel Messages

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