Michael Jackson10
Active Member
140 messages
joined Feb 2023
I haven't had a spare second until now, but here it is—at least my version is a bit shorter:
c=0
istaslova=""
word=input("Enter first word: ")
word2=input("Enter second word: ")
for i in range(len(word)):
--if istaslova.count(word)<min(word.count(word), word2.count(word)):
----istaslova=istaslova+word
----c=c+1
print("Common letters for the words are:",istaslova)
print("Total count:",c)
That last attempt using find() was a total bust, wasn't it? Using find() would have forced me to mess around with some kind of pointer to track progress through the strings...
Anyway, not too shabby for someone who's only had about four hours of Python classes with my nephew in middle school, right??
You should see what I can do with Turtle 🤣
The Syntax trips me up sometimes. I'll have one tab open looking at a W3Schools reference and another on Replit, but man, Python is actually great for learning logic. You can just interpret things instantly or drop in extra code to check variable states. Dealing with those indentation-based structures is a bit of a headache, and I’m constantly double-checking casting since nothing is explicitly declared—I never know if a function expects a specific type or if I just messed up the Syntax... jeez, my last "masterpiece" was back when I was using Cleveland... 🤦
By the way, you didn't really nail the prompt in your first post: it shouldn't be "how many identical letters they have" (since that ignores repeats: "aaaa" and "aaa" only share one unique letter), but rather the "common subset" (because you're treating every single letter as its own entity, regardless of whether that shape already exists in the set)