Python Forum
Delete strings from a list to create a new only number list
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Delete strings from a list to create a new only number list
#5
Quote:But I get [0, 1, 2, 3, 4, 5], the indexes of the complete Char_List is shown instead of the numeric content. Thanks.
The problem is you never referenced the items in the list. This gives you sequence of numbers whose only relation to the list is the count is the same.
for entry in range(len(Char_List)):  # entry is not an item from  the list.  It is a number 0 to 5
Your code would work fine if you checked the actual list values.
Char_List = ['Bla', 'Blu', 10, 20, 30, 40]
Num_List = []
for entry in Char_List:  #<- Loop through the list values
    if type(entry) != str:
        Num_List.append(entry)
print(Num_List)
Reply


Messages In This Thread
RE: Delete strings from a list to create a new only number list - by deanhystad - Apr-27-2023, 01:20 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Strange behavior list of list mmhmjanssen 3 450 May-09-2024, 11:32 AM
Last Post: mmhmjanssen
  [SOLVED] Pad strings to always get three-digit number? Winfried 2 464 Jan-27-2024, 05:23 PM
Last Post: Winfried
  Create X Number of Variables and Assign Data RockBlok 8 1,135 Nov-14-2023, 08:46 AM
Last Post: perfringo
  How to read module/class from list of strings? popular_dog 1 558 Oct-04-2023, 03:08 PM
Last Post: deanhystad
  No matter what I do I get back "List indices must be integers or slices, not list" Radical 4 1,366 Sep-24-2023, 05:03 AM
Last Post: deanhystad
  Trying to understand strings and lists of strings Konstantin23 2 896 Aug-06-2023, 11:42 AM
Last Post: deanhystad
  problem in using int() with a list of strings akbarza 4 844 Jul-19-2023, 06:46 PM
Last Post: deanhystad
  find random numbers that are = to the first 2 number of a list. Frankduc 23 3,534 Apr-05-2023, 07:36 PM
Last Post: Frankduc
  List all possibilities of a nested-list by flattened lists sparkt 1 996 Feb-23-2023, 02:21 PM
Last Post: sparkt
  Help with Logical error processing List of strings dmc8300 3 1,176 Nov-27-2022, 04:10 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

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