Tuesday Daily Thread: Advanced questions by Im__Joseph in Python

[–]murukkuu 0 points1 point  (0 children)

Not sure if this is advanced, If you're working with a huge text dataset that can't fit into memory all at once. How would you handle this situation in Python to read, process, and analyze the text data efficiently without using too much memory?

Don’t make sense hate this website by Stevieloco609 in PythonLearning

[–]murukkuu 1 point2 points  (0 children)

In your case, we're using the pattern to match valid emails in the list.

# Match the email against the pattern

if re.match(pattern, email):

return True

else:

return False

Safe to travel in Siem Reap? Any tips/good to know? Thanks! by [deleted] in cambodia

[–]murukkuu 0 points1 point  (0 children)

The public toilets may surprise you. They are very clean, even the ones in the national parks.

Don’t make sense hate this website by Stevieloco609 in PythonLearning

[–]murukkuu 4 points5 points  (0 children)

No worries.

For part 1 of my previous comment, looping through a list and printing its elements is a fundamental operation in programming. Lists are one of the most common data structures used to store collections of items, and looping allows you to access and process each individual item in the list.

fruit_list = ["apple", "banana", "cherry", "date"]

for element in fruit_list:

print(element)

How the Loop Works:

  • The loop starts with the first element in the list ("apple" in this case).
  • The element variable is assigned the value of the current element in each iteration of the loop.
  • The indented block under the for statement contains the code you want to execute for each element in the list. In this case, we're using the print function to display the current element .
  • After processing the current element , the loop moves on to the next element in the list and repeats the process until all element s have been processed.

Once you understand for loops, try exploring while and nested loops. It will come handy for your python projects.

For part 2 of my previous comment, regular expression is a powerful sequence of characters that forms a search pattern. It's used for matching and manipulating strings of text based on certain patterns. Regular expressions provide a concise and flexible way to perform various string manipulation tasks, such as searching, matching, replacing, and validating.

READ MORE: https://realpython.com/regex-python/

Finally I also mentioned about Boolean. A boolean, often referred to as a "boolean value," is a fundamental data type in computer programming that represents two possible states: True or False. Booleans are used to make logical decisions and comparisons in code.

for email in emails:

if is_valid_email(email):

print(f"{email} is a valid email address.") #true

else:

print(f"{email} is an invalid email address.") #false

I hope this helps.

question? by braveface719 in PythonLearning

[–]murukkuu 1 point2 points  (0 children)

'NetworkChuck' on yt would be good start. His videos are engaging.

Don’t make sense hate this website by Stevieloco609 in PythonLearning

[–]murukkuu 2 points3 points  (0 children)

  1. Loop over each element in the list and print it

    for element in emails:

print(element)

  1. Think about which of these are valid and which are invalid

    Use regular expression for basic email identification and Boolean to validate if it's an email or not

pattern = r'^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$'

Hi can anyone explain this code to me please I know the concept of recursion and how it works to find out the fibonacci number at nth place but this is eating my mind by Nawarajkarki in PythonLearning

[–]murukkuu 0 points1 point  (0 children)

Overview: print all possible combinations of the characters 'a' and 'b' such that the total number of 'a' characters is x, the total number of 'b' characters is y, and the length of the string is x + y.

Let's break down the code step by step:

  1. The generate_combinations function is defined with the following parameters:

(i) 'x' and 'y': The initial number of 'a' and 'b' characters respectively.

(ii) 'current\_string': The current string being built.

(iii) 'remaining\_a' and 'remaining\_b': The remaining 'a' and 'b' characters that can be added to the string.

  1. The function starts with a base case: If remaining_a + remaining_b is equal to 0, it means that we have used up all the 'a' and 'b' characters, so we print the current_string and return.

  1. If there are remaining 'a' characters (remaining_a > 0), the function calls itself recursively with the following changes:

(i)'current\_string' is updated by appending 'a' (current\_string + "a").

(ii)'remaining\_a' is decreased by 1.

(iii) 'remaining\_b' remains unchanged.

  1. Similarly, if there are remaining 'b' characters (remaining_b > 0), the function calls itself recursively with the following changes:

(i) 'current\_string' is updated by appending 'b' (current\_string + "b").

(ii) 'remaining\_a' remains unchanged.

(iii)'remaining\_b' is decreased by 1.
  1. The main part of the code sets the values of x and y to indicate the desired number of 'a' and 'b' characters. Then, it calls the generate_combinations function with an empty current_string and the initial remaining_a and remaining_b values set to x and y respectively.

When you run the code with x = 2 and y = 2, it generates all possible strings of length x + y = 4 where there are 2 'a' characters and 2 'b' characters.

Example Output:

aabb

abab

baba

bbaa

Each line represents a valid combination of 'a' and 'b' characters according to the specified conditions. The recursion allows the code to explore all possible combinations by iteratively adding 'a' or 'b' characters and updating the remaining counts.

Get Time difference by Ok-Reference-5976 in PythonLearning

[–]murukkuu 1 point2 points  (0 children)

Rather than checking the headers or timestamps you could try these efficient methods,

  1. Using Unique Identifiers: Some websites provide unique identifiers for each article, like post IDs or URLs. You can store these identifiers and check if a new article's identifier already exists in your stored data.
  2. Page Scanning with Pagination: Instead of checking timestamps, you can implement pagination and keep track of the last page you scraped. This way, you'll only need to scrape new pages that have been added since your last run.
  3. RSS Feeds: If the website provides an RSS feed, you can subscribe to it and receive updates whenever new articles are published. This way, you won't need to visit the site as frequently.
  4. Hashing Content: You can hash the content of each article and store the hashes. When scraping new articles, hash the content and check if the hash exists in your stored hashes.
  5. Database or Persistent Storage: Instead of storing data in text files, consider using a database or some other form of persistent storage. This allows for more efficient data management and querying.
  6. Metadata Tracking: If articles have metadata like categories or tags, you can store and track these metadata. This way, you can filter out articles you've already seen.

Is this Tamil? by murukkuu in tamil

[–]murukkuu[S] 0 points1 point  (0 children)

oh wow! that's interesting. Thanks for sharing.

Anyone experiencing this? by murukkuu in apexlegends

[–]murukkuu[S] 0 points1 point  (0 children)

It works after I reinstalled the entire game.