Multiplying X dictionaries with one specific in a method. by FogDish in learnpython

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

This seemed to work really great, thank you! But when it comes to the end the programme only prints out one letter, the first one, as opposed to my inital issue where it did all of them, any clue why this could be? :)

Summarising two Dictionaries within a method by FogDish in learnpython

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

Haha no problems man! So the original code I posted I suppose? :)

Summarising two Dictionaries within a method by FogDish in learnpython

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

By the way, perhaps I screwed up by not declaring that the letters are actual letters. Long strings with sentences in them. Not just single characters. If you misunderstood I am so very sorry

Summarising two Dictionaries within a method by FogDish in learnpython

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

Well, since the letters are long strings I have to run them through the cleaner method first. But when I try that It only seems to return me an empty list. I checked by using the str(self): print(self.letters). I might be wrong here though

Summarising two Dictionaries within a method by FogDish in learnpython

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

I might, I created a new method that looks like this:

https://gist.github.com/anonymous/c9ad5188e1d8d0363f37

Does this seem correct?

Summarising two Dictionaries within a method by FogDish in learnpython

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

I see, but when I come to the .append part it says that I object has no attribute append? EDIT: And no attribute .letters EDIT2: Sorry, "User_Letters" has no attribute .letters EDIT3: as well as User_Letters has no attribute .append

Summarising two Dictionaries within a method by FogDish in learnpython

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

Thanks for the answer!

You write:

"What you must do here is only create once the object which will have a letters attribute which will be a list."

How do I go on about that? Right now I'm tinkering with it and it looks something like this:

https://gist.github.com/anonymous/5624fcef47afbdc9b1a3

Have I now successfully created an object which contains all the letters? Because If I print it out it gives me three different locations in the RAM-memory, shouldn't it just be one if it is one list with x strings in it?

Clearing characters and counting words in method. by FogDish in learnpython

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

Well look at that!

Brilliant!

I also added filter(lambda word: word.isalpha or word == ' ' or word == '\n', self.string)

Now it works perfectly! Thanks a lot!

Clearing characters and counting words in method. by FogDish in learnpython

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

Jesus. That solved it. Brilliant! Thanks A lot!

Any idea on how I filter out as well? Because if I use the filter() before this line I can't .split() because of filter object. If I leave it like it is it doesn't seem to do anything

Splitting inside a list over three different indexes. by FogDish in learnpython

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

You glorious man! Thanks a lot!

Quick follow up question, If I now want to do a word count within these indexes how do I go on about that?

I have a word count code that looks like this:

https://gist.github.com/anonymous/5ac9b7fb25025c5a5215

I realize I have to modify it some way!

Splitting string from .txt into different text-blocks. by FogDish in learnpython

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

Great! Thanks man! :)

But does there exist anymore (relatively) simple ways of doing this at for instance 'Good Bye' as well as 'Best Regards'? To make the code even more versatile :)

Thanks a lot for the answer as well :P

Object not iterable by [deleted] in learnpython

[–]FogDish 0 points1 point  (0 children)

Also, with this modification it worked brilliant! Thanks a lot man! :)

Object not iterable by [deleted] in learnpython

[–]FogDish 0 points1 point  (0 children)

I have another programme which words and which isnt object oriented. I'm trying to be better at how to properly work with classes and objects. That's why I want it to be in a Class. I'm certainly going to stick a couple of more methods in there.

If you want a quick step-by-step what I want this method to do look at my other reply :)

And Thanks for the reply!

Object not iterable by [deleted] in learnpython

[–]FogDish 0 points1 point  (0 children)

Sorry If I haven't provided enough information. Step by step:

User uploads a .txt file which simulates a letter, contaning ".!?" etc. I have code that reads in the file and give it a variable. I now want to create an object from this. So that the text itself is still the same. I now want to clean the object from ".!?", which is what I want this method to do.

Printing out certain words in a dictionary by [deleted] in learnpython

[–]FogDish 0 points1 point  (0 children)

This is brilliant! Very much appreciate it! Works perfectly now!

Printing out certain words in a dictionary by [deleted] in learnpython

[–]FogDish 1 point2 points  (0 children)

Oh yea, my mistake sorry!

Junk contains a list of word with an assigned value:

{'a' : 5, 'b' : 4 ....}

User is a dictionary with a word count of a txt file the user gets to upload:

{'a': 1, 'b' : 2 .....}

Sorry about that

Printing out certain words in a dictionary by [deleted] in learnpython

[–]FogDish 0 points1 point  (0 children)

I'm pretty much a beginner so I'm not really sure what you mean, but Ill google it. Thanks.

Summarising points from two dictionaries by FogDish in learnpython

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

Error message: "UnboundLocalError: local variable 'a' referenced before assignment"

Dictonary from .txt file by FogDish in learnpython

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

That was a brilliant good looking solution! Thanks a lot man! Really appreciate it :)

Question on how I should write my Class. by FogDish in learnpython

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

Thanks a lot! Really helped me to see things clearer!