Python Forum
Alpha numeric element list search
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Alpha numeric element list search
#1
I have a list question using the following script:

list1=['a','b','c','d','e','f']
list2=['1A','1B','1C','1a','1b','1c']
list3=[]
list4=[]

for i in list1:
for j in list2:
if i in j: list3.append(j)

for i in list1:
if i not in list3: list4.append(i)

List3 correctly contains:

1a
1b
1c

But list4 contains:

a
b
c
d
e
f

However, if I use ‘if i not in str(list3): list4.append(i)’ list4 correctly lists:

d
e
f

There’s apparently something basic in lists I don’t understand. The numeral 1 seems to cause the original code to fail. For if I delete the 1’s from list2, list4 displays correctly using the original code and not str(list3).

I understand 1 is an integer, but the elements in list2 are strings. ?
Reply


Messages In This Thread
Alpha numeric element list search - by rhubarbpieguy - Apr-01-2020, 12:11 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Numeric Enigma Machine idev 8 259 Yesterday, 02:17 PM
Last Post: idev
  Search Excel File with a list of values huzzug 4 1,148 Nov-03-2023, 05:35 PM
Last Post: huzzug
  list in dicitonary element problem jacksfrustration 3 626 Oct-14-2023, 03:37 PM
Last Post: deanhystad
  alpha advantage api question jacksfrustration 1 449 Oct-09-2023, 03:39 PM
Last Post: Larz60+
  search an element in pandas series learningPython 5 1,373 Apr-30-2023, 08:34 AM
Last Post: learningPython
  Find (each) element from a list in a file tester_V 3 1,157 Nov-15-2022, 08:40 PM
Last Post: tester_V
  Сheck if an element from a list is in another list that contains a namedtuple elnk 8 1,738 Oct-26-2022, 04:03 PM
Last Post: deanhystad
  search a list or tuple for a specific type ot class Skaperen 8 1,855 Jul-22-2022, 10:29 PM
Last Post: Skaperen
  Membership test for an element in a list that is a dict value for a particular key? Mark17 2 1,162 Jul-01-2022, 10:52 PM
Last Post: Pedroski55
  How to find the second lowest element in the list? Anonymous 3 1,907 May-31-2022, 01:58 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