##### Alpha numeric element list search
 Alpha numeric element list search rhubarbpieguy Programmer named Tim Posts: 11 Threads: 5 Joined: Jan 2017 Reputation: 0 Apr-01-2020, 12:11 PM (This post was last modified: Apr-01-2020, 12:13 PM by buran.) 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 pyzyx3qwerty Minister of Silly Walks Posts: 356 Threads: 13 Joined: Mar 2020 Reputation: 9 Apr-01-2020, 12:41 PM The elements that get displayed in list3 are '1a','1b','1c' not 'a','b','c'. Therefore, 'a','b','c','d','e','f' gets printed when you type if i not in list3. However, when you print if i not in str(list3), it looks for the elements inside the words and then prints the right answer. Reply

 Possibly Related Threads… Thread Author Replies Views Last Post Sume Every 10 element in the list and Divided of Sum quest_ 7 148 Nov-27-2020, 10:58 AM Last Post: perfringo Counting Element in Multidimensional List quest_ 1 96 Nov-25-2020, 10:00 PM Last Post: quest_ Adding List Element if Second part of the List Elements are the Same quest_ 3 129 Nov-25-2020, 04:33 PM Last Post: bowlofred Removing element from list squall 6 188 Nov-22-2020, 09:34 PM Last Post: jefsummers 2d Array adds last element to entire list waiteup 2 105 Nov-19-2020, 08:25 PM Last Post: bowlofred How to get index of minimum element between 3 & 8 in list Mekala 2 171 Nov-10-2020, 12:56 PM Last Post: DeaD_EyE Problem printing last element from a list tester_V 3 200 Oct-30-2020, 04:54 AM Last Post: tester_V Finding an element in a 1d list in a 2d array lionrocker221 0 376 Jun-27-2020, 04:50 PM Last Post: lionrocker221 removing dictionary element in list using (key, value) MelonMusk 3 439 Jun-13-2020, 02:37 PM Last Post: buran Search in an unsorted list amir_0402 2 443 Jun-04-2020, 10:25 PM Last Post: deanhystad

Forum Jump:

### User Panel Messages

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