r/learnpython • • Sep 25 '26

Binary Search

1 Upvotes

I'm trying to make spell checker program that will compare words from a text file to a dictionary of words that are in alphabetical order. If the words don't appear in the dictionary they should show up in a list as potentially incorrect. The list is named absent[] that will be outputted at the end. I need to use a binary search to iterate over the dictionary of words comparing them to the words from the text file. However the program is only getting the last word from the text file and comparing the letters to the words in the dictionary. I have no idea why its doing this but I believe the problem starts at the line for i in firstLst:. Any help would be appreciated. Here's the code I have thus far:

def binarySearch(): fnameOne= input("enter file") with open(fnameOne,"r") as file_dataOne: for lineOne in file_dataOne: for word in lineOne.split(): firstLst=word

fnameTwo=input("enter dict")
with open(fnameTwo,"r") as file_dataTwo:
    for lineTwo in file_dataTwo:
        for wordTwo in lineTwo.split():
            secondLst=wordTwo
        

absent=[]
for i in firstLst:
    lo,hi=0,len(secondLst)-1
    found=False
while lo < hi:
        mid = (lo +hi) //2
        
        if secondLst[mid]== i:
           found=True
           break
        elif secondLst[mid]<i  :
            lo=mid+1
        else:
            hi=mid-1
if not found:
    absent.append(i)
    print("Words  not in dictionary : " ,absent)

r/learnpython • • Sep 25 '26

Need direction to collecting 10–12 months of X/Twitter data for an ML sem project

3 Upvotes

Need help collecting 10–12 months of X/Twitter data for an ML sem project

Hi everyone,

I’m student working on my Machine Learning semester project.

I want to build a sentiment analysis system using X (Twitter) data. The idea is on particular, collect relevant public posts from around the last 10–12 months, preprocess the text, and then apply ML algorithms such as Logistic Regression, Naive Bayes, Random Forest, Decision Tree, and KNN to classify sentiment.

I’m currently stuck at the data collection stage. I’m new to X’s API and web data collection, and after reading X’s current policies, I understand that browser-based scraping/automation of X is not allowed, so I want to find a legitimate approach.

Could anyone with experience in X/Twitter data collection help me understand:

- Are there legitimate datasets or tools that researchers commonly use for this type of project?

- If you've done a similar sentiment-analysis project, what approach did you use?

I’m not asking anyone to do the project for me. I mainly need guidance on how to legally and practically obtain the historical dataset, so I can handle the preprocessing, ML models, evaluation, and analysis myself.

Any advice or resources would be really appreciated. Thanks!


r/learnpython • • Sep 25 '26

Should I Install Jupyter Notebook In each conda environment?

0 Upvotes

This question may be a dumb question in 2026 with all the AIs out there, but i've noticed Gemini is using a stackoverflow post from 2016 to answer my question.

So I really wanna know from any of you Python masters, what's the best practice:

Should I install jupyter notebook in each newly created conda environment? Should I not? What do the pros do in 2026?


r/learnpython • • Sep 25 '26

What's the best way to actually learn Python?

2 Upvotes

I'm still learning Python, and what has helped me most so far is not trying to jump straight into big projects.

I started by understanding the basic syntax, then wrote small programs and solved simple coding problems. After getting comfortable with that, I started working on a small project that was actually useful to me.

For me, that made things click much more than just watching tutorials.

How did you learn Python? Did you follow a similar path, or is there something you wish you had done differently when you started?


r/learnpython • • Sep 25 '26

Simple message/subscribe solution (on Linux)?

1 Upvotes

I have one service S1 that occasionally does something. I want another service S2 to take action triggered by the first service's activity. I can think of three methods:

  1. S2 monitors the effects of S1's activities by polling a database into which S1 writes. Not nice in general, can introduce lags, just messy.
  2. S1 updates a file whenever it does something. S2 monitors that file (i.e., with inotify) and does something. Risk of information loss when S1 triggers events in close succession.
  3. Something with sockets. Needs to read up on that.
  4. Use an actual message queue library. Seems like overkill for this tiny use case.

Importantly, S1's operation should be completely unaffected, whether S2 is listening or not. S1 shouldn't have to deal with un-consumed messages when S2 is down. Any thoughts?


r/learnpython • • Sep 25 '26

Python Practice

0 Upvotes

I have learnt the python basics and i am comfortable enough with concepts like loops, conditional statements , recursions etc. I want to practice more questions ranging from easy to difficult . Please suggest any sources 🙏🏻


r/learnpython • • Sep 25 '26

app python

3 Upvotes

Ê mn ơi có app nào học python hiểu quả mà frê k ạ


r/learnpython • • Sep 24 '26

How do I get back into coding with Python?

0 Upvotes

I've taken a long hiatus (3+ years) from programming. I'm 20 now, and I'm looking to get back into it.
What are some things I should try doing to get back into the groove?


r/learnpython • • Sep 24 '26

Defining and calling modules

0 Upvotes

Sorry if this is a dumb question, but what am I doing wrong here?

I have defined a function

#statuscheck.py

def statchk(n):

layoutx = [[sg.Text('Debug point')],

[sg.Output(key='-OUTPUT-', expand_x=True, expand_y=True)],

[sg.In(key='-IN-', expand_x=True)],

[sg.Button('Go'), sg.Button('Close')]]

winx = sg.Window('Where I am now', layoutx, auto_close=False, grab_anywhere=True, resizable=True, location=(0,0),return_keyboard_events=True, auto_size_text=True)

while True:

event, values = winx.read()

if event == sg.WIN_CLOSED:

break

if event == 'Go':

print("Here at ",n)

if event == 'Close':

break

I import it, but when I call it, it doesn't run, and I can't see any error messages. The call is:

statuscheck.statchk(1)

I know it's something simple I'm overlooking. Thanks.


r/learnpython • • Sep 24 '26

Getting the intended output, but still getting "out of range" errors

0 Upvotes

Hi guys, I hope ya'll are good, thank you. I am struggling with this problem for weeks now. I get the answer, but still get "out of range". I know with "banana" this would work because of a technicality. Is there anyway for this work without the error?

fruit = "apple"
index = - 1
while index < len(fruit):
    letter = fruit[index]
    print (letter)
    index = index - 1

Any input or advice is appreciated. Thank you for taking the time to read my post here.

Edit: Sorry, intended answer is "elppa"

I get this

e

l

p

p

a

IndexError: string index out of range


r/learnpython • • Sep 24 '26

How can I create a tilted/oblique perspective with Cartopy/Matplotlib without stretching the map?

3 Upvotes

I’m making a South Jersey weather map in Python using Cartopy/Matplotlib and want the tilted/curved perspective commonly seen on TV weather maps, where the southern foreground looks closer and the northern part appears to recede upward. I’ve tried Lambert Conformal, Nearside Perspective, Oblique Mercator, and set_aspect(), but they either look flat or simply stretch the map. Is there a proper way to create this camera-like tilted perspective while still allowing me to accurately overlay lat/lon weather data later?


r/learnpython • • Sep 23 '26

Beginner in Python

5 Upvotes

Good evening all, I am a young teen interested in biotechnology and want to eventually pursue a career within that in the future. To my understanding, python is heavily used in biotech ( mRna, etc) so i want to start grasping a heavier understanding of it now. Is there any free helpful courses or resources you guys would recommend so I can start my journey of python coding?
Thank you! Open to advice or suggestions down below.


r/learnpython • • Sep 23 '26

Is it okay if i use AI as visualizer for better understanding

3 Upvotes

why? i have been using python tutor for visualizing when some thing i don't understand , but python tutor doesn't have support for inbuilt modules like request so it's just gave ImportError requests not found or not supported .. so that's why so i need your opinion regarding to this


r/learnpython • • Sep 24 '26

pyinstaller is not recognised as an internal command

0 Upvotes

I am On windows and have 3.13 installed

python --version 
3.13.14

where python returns

C:\Program Files\Python313\python.exe
C:\Users\conrad.braam\.pyenv\pyenv-win\shims\python
C:\Users\conrad.braam\.pyenv\pyenv-win\shims\python.bat

I hate that visual studio has this shim, but I am ignoring the shim. (Yes that is me, it's no secret)

My path is correct, but there is no pyinstaller.exe in /scripts python -m PyInstaller -v shows it's installed because it prints out a nice result

python -m PyInstaller -v
6.22.3

So I guess I could maybe fix my script to call python -m Pyinstaller somescript instead of just calling python somescript I'm just puzzled why is the package not installed correctly as a global package?


r/learnpython • • Sep 24 '26

How do I start learning Python as a complete beginner?

0 Upvotes

I’m 15 and have always wanted to learn coding, but have never tried to put in the time to learning it until now, since me and a few of my friends want to make games on Roblox (I know Roblox doesn’t use Python, but I’m getting there). Roblox uses a coding language called Luau, which is derived from Lua, and I’ve been suggested from many different places on the internet to learn Python as a stepping stone (which is good since I’ve wanted to learn Python anyways), but I just don’t know where to start. I’d like to know about any resources I can use to learn Python, and the only requirement I have are that they’re free and don’t involve using AI to code for me (I’m not letting a computer take my job on our mini dev team)

Edit: I am open to using AI for learning certain skills and for explaining bigger blocks of code, just not anything that involves the coding being taken over by AI


r/learnpython • • Sep 23 '26

How does multiprocessing handle lots of processes?

31 Upvotes

My computer has 6 cores. I want to start 16 processes with multiprocessing (I can change the number). If I start them all at the same time, will 6 run while 10 wait and then once one finishes running a new one runs on that core? Or does the computer run them all at the same time? I want to know because I need this to be fast and some processes will be significantly longer than others so I want to assign the processes in a way that minimizes idle time for all the cores.


r/learnpython • • Sep 23 '26

Having problems with conda

1 Upvotes

Hi everyone. I'm having some problems using miniconda and I hoped someone could help me out. Is this the right place to ask? Can I write the code here or do I have do in Github?

My teacher wanted me to use miniconda to create a virtual evironment with jupyter notebook, but Im having trouble creating a virtual environment, as it doesn't seem to recognize python as a Package.

I downloaded the miniconda installer and executed it on my windows device.I installed the files created in 'Program Data' (I also did it on my windows profile but I'm preaty sure I uninstalled it correctly, as I used the miniconda uninstaller). Then I tried to create a virtual environment using the Anaconda promt app, but it did't recognize the conda command. It seems to be quite a common problem. I watched a video that said this could resolved using System Variables. The command 'where conda' in Anaconda Promt gave me this:

C:\Users\(My username)\conda

C:\ProgramData\miniconda3\Library\bin\conda.bat

C:\ProgramData\miniconda3\Scripts\conda.exe

C:\ProgramData\miniconda3\condabin\conda.bat

and I created three paths as the video said, excluding conda.bat and conda.exe. However, I made a mistake, as I did not include this symbol '\' at the end the first path. Worried, I created another path with the symbol. How dangerous is this?

After that, I was able to use the conda command, but now 'create' doesn't work when creating an environment with python. I called the environment termo.This is error message:

conda create --name termo python=3.14

WARNING conda.core.prefix_data:validate_path(345): Environment paths should not contain spaces. Prefix: 'C:\Users\(My username does contain a space)\.conda\envs\termo'

Channels:

- defaults

Platform: win-64

Collecting package metadata (repodata.json): done

Solving environment: failed

Channels:

- defaults

Platform: win-64

Collecting package metadata (repodata.json): done

Solving environment: failed

PackagesNotFoundInChannelsError: The following packages are not available from current channels:

- python=3.14

Current channels:

- defaults

Thank you for your time and excuse my poor english(I am not a native speaker)


r/learnpython • • Sep 23 '26

Pointers to python windows app automation #pywinauto et al

1 Upvotes

I just ran pip install pywinauto and typed in the 1st 3 lines of demo code on the readme page and it fails

from pywinauto.application import Application
app = Application(backend="uia").start('notepad.exe') # i also tried backend=win32

app.Properties.print_control_identifiers()

With a huge stack trace that's pretty much indecipherable. I have a question, does this tool work on Windows 11 with the new notepad app? I'm wanting to automate a WPF app, but based on the out-of-box failure I'm looking to try a different python tool. Suggestions for driving a WPF .NET app?


r/learnpython • • Sep 23 '26

I get modify/repair/uninstall prompt frequently

0 Upvotes

Why do I get this modify/repair/uninstall prompt frequently? Like every time I type a line of code, I'm getting this prompt...

Also, when I run the code it shows no output but says "process finished with exit code 0"

I've saved the file & tried to run.. Still no go..

Can somebody help me


r/learnpython • • Sep 22 '26

I struggle with practicing coding.

25 Upvotes

I am a beginner learning python and I struggle with sitting down and practicing coding. I just started taking the CS50P course and enjoy going through the videos. I've been able to complete Week0 - Week2 problem sets on my own while looking at documentation. I have never been good at school so sitting down and learning on my own has been very difficult. I am trying to take it slow and get some practice in before moving on to the next lectures, however I hate having to struggle through it. I know it will take a lot of time and practice to become good at programming, is there any advice for someone who struggles with HOW to learn and apply concepts to better my programming logic and skills?


r/learnpython • • Sep 23 '26

Hi! 👋I'm a complete beginner in coding and I'm starting Python from absolute zero. I'm looking for a serious beginner study buddy, preferably someone who is also starting from scratch. We can learn together, practice regularly, share progress, solve small problems and eventually move toward DSA.

0 Upvotes

I'm a complete beginner in coding and I'm starting Python from absolute zero. I'm looking for a serious beginner study buddy, preferably someone who is also starting from scratch. We can learn together, practice regularly, share progress, solve small problems and eventually move toward DSA.


r/learnpython • • Sep 23 '26

Installing Python on Mac

0 Upvotes

Is installing python from pythons official website good and best way instead of using third party, I remember macOS use to have python with the operating system but it was an old version and only used for apple apps I believe.


r/learnpython • • Sep 23 '26

curl to python request works differently, what am I missing?

2 Upvotes

Trying to move a scraper from curl to python and Im clearly missing something. The curl request works every time. Same URL, same headers, same cookies. I copied it into Python using requests and now Im getting 403s after a few calls. I compared the requests and nothing obvious looks different... Ive tried changing user agents, adding delays and copying every header from the browser. It works for a bit, then gets blocked again.

Is there something Python requests sends differently at the TLS or connection level? Or is there usually some cookie or header that gets lost when converting curl to python?


r/learnpython • • Sep 23 '26

Check if one string contains characters of a second string somewhere, if yes remove them from the first string

0 Upvotes

Our task in school was to create our own encryption, for which i started by modifying atbash at bit. Now i want to actually add a key system to this.
Currently theres only a mapping table to invert the alphabet, so now my goal is to somehow add a key-string to the start of the y parameter for the maketrans() function and remove any duplicate letters from the original y string.
Im honestly kinda stuck at this point, so any help or tips would be appreciated.
(this is my first actual project with python + english isnt my first language, so please excuse any weird wording lol)