I have been looking through numerous questions that seem like they hit the nail on the head, but then end up confusing me further and end up not helping at all. So hopefully no one closes this question and refers me to other questions, and actually helps me because I have spent hours trying to figure it out. I cannot provide the actual text for security reasons so I will make up similar looking lists. There are thousands of strings in these list but ill just make an example of 3, purposely putting in strings that I want to match up.
list= ['93900 2016-01-11.50 10.17', '93030 2014-04-16.50 18.83', '29322 2009-05-21.50 17.81']
list1= ['33492 2017-02-14.50 11.17', '93900 2016-02-11.00 11.15', '93900 2016-12-14.00 15.66']
- list has different spacing between the characters
- I need to take for example in "list", 93900 2016-01-11.50 10.17 and compare to the strings in list1, and ask if 93900 along with the date 2016-01-11.50 but with a +-month buffer. So ideally it would return '93900 2016-02-11.00 11.15', '93900 2015-12-14.00 15.66' from list1. I only know how to compare exact strings that are either exactly the same or not. This is more complicated because if I do that comparison it will clearly return an empty list because none of them will match. I need a smarter code that will look within the string and allow me to look for values near it. I also need to put the full string into a new list after compared, not the partial string.
I hope this makes sense and that someone can help.
All I have is a nested loop that does not work because I cannot figure out how to compare partial strings.
new_list= [] for line in list: for line1 in list1: if line[0:5] in line1[0:5] new_list.append[line]
Yeh this clearly does not work but its a way to check one agains each element in the list, but not certain characters.