#๐Ÿ”’ Check 2 lists for an equal sequence

58 messages ยท Page 1 of 1 (latest)

white ospreyBOT
#

@stiff wave

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

stiff wave
#

wtf the bot deleted my whole message because i didnt use syntax?

crude rampart
#

Yup or it was too long

#

!paste

white ospreyBOT
#
Pasting large amounts of code

If your code is too long to fit in a codeblock in Discord, you can paste your code here:
https://paste.pythondiscord.com/

After pasting your code, save it by clicking the Paste! button in the bottom left, or by pressing CTRL + S. After doing that, you will be navigated to the new paste's page. Copy the URL and post it here so others can see it.

stiff wave
#

Welp that really sucks, I typed a lot.

#

Aight I'll type it again

crude rampart
#

Lesson learned. Don't use discord as a text editor

stiff wave
#

I have a flightsCSV list a compareList list. I need to find if a sequence on the compare list matches a sequence on the flightsCSV list.

flightsCSV look like this: https://paste.pythondiscord.com/X5XQ
compareList, as an example, looks like this: https://paste.pythondiscord.com/TXEA

There are 2 conditions for matching sequences:

  1. The sequence can start at any position of compareList but must start at the first entry of CS-0015 in flightsCSV
  2. The sequence must have at least 3 in a row to be considered a sequence unless there are 3 or less entries of CS-0015 in flightsCSV
#

*CS-0015 was just an example but could be any CS-XXXX. Although compareList will only contain 1 kind of CS-XXXX at a time

crude rampart
#

So because of #2, what's the point of compareList being longer than 3 entries?

stiff wave
#

I was going to correct something

#

scratch condition 2

crude rampart
#

ok

frosty valley
#

something like this?
list_of_duplicates = [x for x in flights_csv if x in compare_list]

#

It filters through each embedded listin flights_csv and checks if it is in the compare list, then saves all that to a list

crude rampart
#

But that's not looking for an entire sequence though

#

just single entries that are in both

stiff wave
#

The 2nd condition is that once the sequence start it must continue until the end of 1 of the lists or both as long as they are the same CS-XXXX

#

Doesn't matter the size

crude rampart
#

ok

frosty valley
#

is the sequence provided?

crude rampart
#

Then my question still is valid - what's the point of the first N-3 entries in compareList?

#

if the only ones that matter are the last 3

stiff wave
stiff wave
#

Might not start at compareList[0]

#

But will always end at compareList[19]

#

which is as high as it will go

#

forgot to mention that

crude rampart
stiff wave
#

no

crude rampart
#

really?

frosty valley
#

Would just in work then?

crude rampart
#

If they were, you could just count the number of times compareList[-1] exists in flightsCSV

stiff wave
#

for example ['CS-009', '98291', '0', '3', '30'] in flightsCSV

stiff wave
crude rampart
#

but there can be duplicates in compareList also though?

stiff wave
#

yep

#

Might be easier to understand if I give the actual scenario where that is being used

crude rampart
#

ok so what about
flightsCSV = [a, b, c, a, b]
compareList = [c, a, b]

What's the "answer" for this scenario?

stiff wave
#

the sequence would be a,b
because the sequence must always start at the first position of flightsCSV

#

although compareList could never be smaller than flightsCSV

crude rampart
#

every message yuo send confuses me even more

stiff wave
#

Sorry english isn't my first language and I might not explain it clearly

crude rampart
frosty valley
stiff wave
#

the entries of CS-0015 in flightsCSV could never be smaller than compareList

#

This is the real scenario:
I'm scrapping a website that has a list.
That list has a limit of 20 rows.
Each new row is added on top, consequently each oldest row is removed from the bottom.

Each time i scrape I retrieve that 20 rows list. Which could be anywhere from 1 row to the full 20 rows.

There is nothing to identify each row in the webiste (no id= or class= or patterns).

frosty valley
#

!rule 5

white ospreyBOT
#

5. Do not provide or request help on projects that may violate terms of service, or that may be deemed inappropriate, malicious, or illegal.

stiff wave
#

Ah no no, it's from a game, the devs actually allow people to do it for spreadsheets and stuff

frosty valley
#

Oh ok, I would look at zip() in for loops then, it might help

white ospreyBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.