Ask coding questions

← Back to all posts
How to process and edit lists in a loop
Madeline69 (0)

I'm trying to make a program where you can input a word and it'll create list(s) (I'm not sure if I only need one list with different copies of the list or multiple different lists) with random values (EX: ['s','a','f','e']) that is the same length as the word you put in. Then it'll look at those list(s) and keep the values that match the user given word and replace the values that don't match with random values. I want it to repeat this process until there's one list that completely matches the user given word.

I've gotten it to generate a random list and check/ replace the random list values but only once (at least when testing it by using a set "random" list. You can see the list I use to test in the code below)

So my question is, how do I make it so that it'll keep looping and replacing values until they all match the user given word?

I'm just confused on if I need to be adding the random list(s) to a data base or is it fine to have them stored how they are?

And if they do need to be in a db, how would I go about doing that?

Also, should I be using lists or would it be easier/ possible to do this with just strings?

Thanks in advance! :)

Comments
hotnewtop
IntellectualGuy (710)

There's a way that it doesn't have to do keep on replacing at all, just use a for loop

word = input("Enter a word: ")
letter_list = []
for x in word:
   letter_list.append(x)
Madeline69 (0)

@IAmNew1234
okay first of, that made me laugh harder then it should have

second off, if you have a better suggestion please feel free to share :)
(not to be rude in anyway I'm just genuinely trying to figure this out)

Madeline69 (0)

@IntellectualGuy
Thank you for the suggestion!

I tried this out but the issue is that it doesn't replace the values in the random list, it just adds new values on to the end of the list

any suggestions?

IAmNew1234 (10)

@Madeline69 i might have some people in my team that could fix this

IAmNew1234 (10)

@Madeline69 ill add you to the team and you should make a repl for the team stating what you need hel with and hopefully someone on my team can help out soon

IntellectualGuy (710)

@Madeline69 Maybe just redefine the list to have no values or make a different list that doesn't have anything

Madeline69 (0)

@IAmNew1234
I don't necessarily need someone to fix it I just need someone to show me ways I could possibly fix it (so that I can learn how to do this for future projects)

but if you know anyone that has any suggestions on what to do, if you could let me know that would be great!

Madeline69 (0)

@IAmNew1234
okay I'll check it out :)

IAmNew1234 (10)

ok here are some people who could help and tell u @Madeline69
1. QEREWRAD
2. GEISTCODER
3. GalaxyWolfX

IntellectualGuy (710)

@Madeline69 Did you even see my message?

Madeline69 (0)

@IntellectualGuy
I'm so sorry!! I totally missed your other messages!

While technically just keeping the list empty gives me the result of the list matching the user given word its not quite what I'm trying to do. What I'm trying to do is I'm trying to make it so that the program will, through trial and error, start with a completely random list and end up with a list that matches the user given list.

That being said I really really appreciate the help!! :)

Madeline69 (0)

@IAmNew1234
Okay thank you so much!! I'll make a team repel and see if anyone can help :)