CheckEmoji Community · the emoji forum
🏠 Home 🆕 What's new ❓ Unanswered 🔥 Popular 📡 RSS Members 👥 0 online log in · register
Home › IT › IT Support › Word Comparison

Word Comparison

Started by coastaltiger39 · · 👁 8 views · 33 replies

📡 Subscribe to replies

Participants coastaltiger39bluecyclist64Michelle Bennett5Benjamin Brooks2Michael Jackson10
Michelle Bennett5 Michelle Bennett5 Active Member
89 messages
joined Dec 2007
#21 ·
Michael Jackson10 said:Nah, he's actually right. I totally misread the prompt—I thought we weren't supposed to count duplicate letters...

Whatever, just comment out that second if statement

Just a heads up—if you follow the instructions (like with "apple" or "egg"), the answer should be 2. If you just comment that part out, you're gonna end up with 3.
You really need an array to track which letters from the first word have already been used, otherwise, there's no way to pull this off.
Benjamin Brooks2 Benjamin Brooks2 Member
27 messages
joined Jun 2020
#22 ·
Michelle Bennett5 said:Just a heads up—if you follow the instructions (like with "apple" or "egg"), the answer should be 2. If you just comment that part out, you're gonna end up with 3.
You really need an array to track which letters from the first word have already been used, otherwise, there's no way to pull this off.

Never touched Python before, but I guess it would look like this

c=0
istaslova=""
sentence=input("Enter the first sentence: ")
sentence2=input("Enter the second sentence: ")
for i in range(len(sentence)):
for j in range(len(sentence2)):
for c1 in range(len(istaslova))
if sentence2.find(sentence)********* if it found the same letter in both words
if istaslova.NOTfind istaslova = istaslova + ......c=c+1****** if it DIDN'T find the letter in "istaslova", then add it

print("Repeating letters:",istaslova)
print("Total count:",c)
Benjamin Brooks2 Benjamin Brooks2 Member
27 messages
joined Jun 2020
#23 ·
Michelle Bennett5 said:Just a heads up—if you follow the instructions (like with "apple" or "egg"), the answer should be 2. If you just comment that part out, you're gonna end up with 3.
You really need an array to track which letters from the first word have already been used, otherwise, there's no way to pull this off.

😁 You'd probably overcomplicate black holes and event horizons too, along with space curvature and gravity
Michelle Bennett5 Michelle Bennett5 Active Member
89 messages
joined Dec 2007
#24 ·
Benjamin Brooks2 says:
I've never touched Python before, but I figure it would go something like this...

c=0
istaslova=""
sentence=input("Enter the first sentence: ")
sentence2=input("Enter the second sentence: ")
for i in range(len(sentence)):
for j in range(len(sentence2)):
for c1 in range(len(istaslova))
if sentence2.find(sentence)********* if it found the same letter in both words
if istaslova.NOTfind istaslova = istaslova + ......c=c+1****** if it DIDN'T find the letter in "istaslova" already, then add the letter

print("Duplicate letters:",istaslova)
print("Total count:",c)

It’s not gonna work like that. Check post #3; I already went over this there.
You need some kind of status matrix for every position in that first word—something to track what's been used up, right?
Benjamin Brooks2 Benjamin Brooks2 Member
27 messages
joined Jun 2020
#25 ·
Michelle Bennett5 said:
Benjamin Brooks2 says:
I've never touched Python before, but I figure it would go something like this...

c=0
istaslova=""
sentence=input("Enter the first sentence: ")
sentence2=input("Enter the second sentence: ")
for i in range(len(sentence)):
for j in range(len(sentence2)):
for c1 in range(len(istaslova))
if sentence2.find(sentence)********* if it found the same letter in both words
if istaslova.NOTfind istaslova = istaslova + ......c=c+1****** if it DIDN'T find the letter in "istaslova" already, then add the letter

print("Duplicate letters:",istaslova)
print("Total count:",c)

It’s not gonna work like that. Check post #3; I already went over this there.
You need some kind of status matrix for every position in that first word—something to track what's been used up, right?

Fine, here's my first attempt at Python

Python C = 0
a = "Benjamin Brooks2"
b = "Michelle Bennett5"
common_chars = ""
for x in a:
- for y in b:
-- if x == y:
--- if x not in common_chars:
---- common_chars = common_chars + x
---- Python C = 0
print(c)

********************

I don't see any matrices here... maybe something else is going on at your event horizon, because I didn't even use "Used" 🤔

EDIT: Okay, I get what you mean about the dashes now
Benjamin Brooks2 Benjamin Brooks2 Member
27 messages
joined Jun 2020
#26 ·
c = 0
a = "Benjamin Brooks2"
b = "Michelle Bennett5 Kok"
istaslova = ""
for x in a:
for y in b:
if x == y:
if x not in istaslova:
istaslova = istaslova + x
c = c + 1
print(c)
print(istaslova)
Michelle Bennett5 Michelle Bennett5 Active Member
89 messages
joined Dec 2007
#27 ·
Benjamin Brooks2 said:c = 0
a = "Benjamin Brooks2"
b = "Michelle Bennett5 Kok"
istaslova = ""
for x in a:
for y in b:
if x == y:
if x not in istaslova:
istaslova = istaslova + x
c = c + 1
print(c)
print(istaslova)

It's fine, I guess, but if you actually want to solve the problem correctly, you have to match those specific examples from the very first post. That's where the real trick is hidden.
Benjamin Brooks2 Benjamin Brooks2 Member
27 messages
joined Jun 2020
#28 ·
Michelle Bennett5 said:It's fine, I guess, but if you actually want to solve the problem correctly, you have to match those specific examples from the very first post. That's where the real trick is hidden.

c = 0
a = "potato"
b = "bread"
common_letters = ""
for x in a:
for y in b:
if x == y:
if x not in common_letters:
common_letters = common_letters + x
c = c + 1
print(c)
print (common_letters)

Who writes a program relying on food when we've got boolean usage matrices right here?

We aren't in a biology lab. Imagine your breaker trips and you start listing which appliances lost power...

I see you struggling to plug apples, eggs, butter, potatoes, and bread into the code. It's just what's inside the quotes; delete them and put whatever you want.
Michael Jackson10 Michael Jackson10 Active Member
140 messages
joined Feb 2023
#29 ·
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)
Michelle Bennett5 Michelle Bennett5 Active Member
89 messages
joined Dec 2007
#30 ·
Michael Jackson10 says:
I haven't had a spare second until now, but here it is. At least, this is my version of a shorter way:

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 are:",istaslova)
print("Total count:",c)

That previous example using find() was a total disaster, because if you use find(), you have to come up with some kind of pointer logic to track where you are moving through the words...

Anyway, isn't this decent for someone who’s only had about four hours of Python classes while helping out a middle schooler nephew??
You should see me trying to mess around with Turtle 🤣
The Syntax trips me up sometimes. I've got one tab glued to a W3Schools reference and another on Replit, but Python is actually pretty sweet for learning logical structure. You can interpret things immediately or just drop in some code to check variable states. It's a bit of a pain with these indentation-only structures, and I'm constantly checking my casting since nothing is declared—I'm never quite sure what a function expects or if I just botched the Syntax... man, my last "masterpiece" was back when I was messing with Cleveland... 🤦

Besides, you didn't really define the task right in your first post: it's not "how many identical letters they have" (since that doesn't account for repeats: "aaaa" and "aaa" only share one unique letter), it's a "common subset" (where you treat every single letter as its own entity, regardless of whether the shape exists elsewhere in the set)

count() is a pretty powerful method; it gives you the quantity right away

I didn't define the task; the definition is actually hidden in the examples. You have to read between the lines.

And Cleveland isn't that bad. I still see old Cleveland/87 PC cases all over town.
Benjamin Brooks2 Benjamin Brooks2 Member
27 messages
joined Jun 2020
#31 ·
Michael Jackson10 says:
Haven't had the time until now, but here it is. At least, this is my shorter version:

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)

My previous attempt using find() was a complete bust. You'd have to manage some kind of pointer to track where you are in the words...

Anyway, isn't this decent for someone who's only had about 4 hours of Python classes with a nephew in middle school?
Wait until you see me struggle with Turtle 🤣
The Syntax trips me up. I've got one tab open with a W3Schools reference and another on Replit, but Python is actually pretty good for learning logic. You can interpret it instantly or drop in code to check variable states. The indentation-only structure is a pain, and I'm constantly checking casting since nothing is declared—I'm never sure what a function accepts or if I just messed up the Syntax... damn, my last "masterpiece" was in Cleveland... 🤦

Besides, you didn't even define the task right in your first post. It wasn't "how many identical letters they have" (since that ignores repeats: "aaaa" and "aaa" only share one unique letter), it's a "common subset" (where you treat every single letter as its own entity regardless of shape)

Man, we should start a new thread for coding challenges. We could post problems and try to hunt down solutions online, though people would probably accuse us of being "intellectually dishonest" or whatever. Is there anyone here doing actual "coding" who isn't intellectually dishonest, or are we just going to play around with Syntax errors?

Is there a thread for problem-solving? Not just Syntax, but actual discussion on how things should be done?
Benjamin Brooks2 Benjamin Brooks2 Member
27 messages
joined Jun 2020
#32 ·
Can someone start a new thread? Not sure if one exists. I want to actually solve code issues instead of dealing with all this nonsense. Or should we just pivot to arguing about Civil War history? What do you guys prefer?
Michael Jackson10 Michael Jackson10 Active Member
140 messages
joined Feb 2023
#33 ·
Benjamin Brooks2 said:
Michael Jackson10 says:
Haven't had the time until now, but here it is. At least, this is my shorter version:

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)

My previous attempt using find() was a complete bust. You'd have to manage some kind of pointer to track where you are in the words...

Anyway, isn't this decent for someone who's only had about 4 hours of Python classes with a nephew in middle school?
Wait until you see me struggle with Turtle 🤣
The Syntax trips me up. I've got one tab open with a W3Schools reference and another on Replit, but Python is actually pretty good for learning logic. You can interpret it instantly or drop in code to check variable states. The indentation-only structure is a pain, and I'm constantly checking casting since nothing is declared—I'm never sure what a function accepts or if I just messed up the Syntax... damn, my last "masterpiece" was in Cleveland... 🤦

Besides, you didn't even define the task right in your first post. It wasn't "how many identical letters they have" (since that ignores repeats: "aaaa" and "aaa" only share one unique letter), it's a "common subset" (where you treat every single letter as its own entity regardless of shape)

Man, we should start a new thread for coding challenges. We could post problems and try to hunt down solutions online, though people would probably accuse us of being "intellectually dishonest" or whatever. Is there anyone here doing actual "coding" who isn't intellectually dishonest, or are we just going to play around with Syntax errors?

Is there a thread for problem-solving? Not just Syntax, but actual discussion on how things should be done?

Sorry, I didn't quite catch that: are you implying I just ripped this off the internet?
I told you I was following a tutorial and some W3C reference while using an online interpreter—I wasn't looking for a shortcut...
So go ahead, hit me with a link to the "original."

For me, this was just a fun little challenge since I had to wrap my head around Python basics to help out my nephew. It's not like I'm planning on making a career out of it; I'm already pulling 9-10 hour shifts in a totally different industry...
Michelle Bennett5 Michelle Bennett5 Active Member
89 messages
joined Dec 2007
#34 ·
Hey, quick question—can I just feed the text from the first post directly into AlphaGo and expect it to spit out some Python code? Assuming, of course, that I’ve already fed it all the Python syntax rules.

You must log in or register to reply here.

Log in Register

🔗 Similar threads