![]() |
|
Python help thread? - Printable Version +- Southperry.net (https://www.southperry.net) +-- Forum: Social (https://www.southperry.net/forumdisplay.php?fid=14) +--- Forum: Rubik's Cube (https://www.southperry.net/forumdisplay.php?fid=58) +--- Thread: Python help thread? (/showthread.php?tid=37777) |
Python help thread? - EarthAdept2 - 2011-03-04 I'm converting a string to an integer value. That was what I was taught, so I dunno. If input() will allow me to get an immediate integer value, I'll keep that in mind. If you have the time to give me a little extra advice to shorten the code, I'd be happy to receive that. But I'm mostly just looking for a confirmation (since it's due today lolol). For above code: You can use (if word[0].lower in (insert your conditions here) to shorten up the line.From what I understand, you're looking to continue the search through the entire string. If that's the case, you need to set up the string index as a variable which will add onto itself in a loop. Ex. Index = index + 1 -> word[index] So this will go through the entire string each letter at a time. But since this site is full of python pros, I think I'll just leave it for those guys to give you an even shorter method. Python help thread? - Fiel - 2011-03-05 You don't really need an index for a string in python unless you're going to be doing string splitting: Code: x='spam'Code: sCode: from string import *Much better: Code: def IsVowel(letter):Code: >>> Also, make sure you have the parenthesis in there. word[0].lower() Otherwise you're going to receive the memory address for the method. Code: >>> word = 'X'Lastly, you don't need to import string to get access to the lower method. That's a built-in. Python help thread? - JPTheMonkey - 2011-03-05 Fiel Wrote:You don't really need an index for a string in python unless you're going to be doing string splitting Which is what should be going on. I can get it up to the first consonant, but I have to also strip all others up to the vowel, which is the source of my confusion. Examples would be: Yvonne = Yvonne-ay Yesterday = esterday-Yay Friday = iday-Fray always = always-ay And for some reason he (my teacher) also has it checking for double consonants (bulldog) and removing one. Not sure if this was a typo or not, though. Python help thread? - Fiel - 2011-03-06 Code: def GetFirstVowelIndex(inputString):Code: import rePython help thread? - EarthAdept2 - 2011-03-14 Simple enough question: I have two lists. I want to the 2nd one to be a sorted list of the 1st one while keeping the original as it is. Is there a function I can use or would I actually have to separately program it and manually make a new list? Example of what I don't want happening: Code: c = [1,5,6,3,2,10]They come out as both being sorted. I'm not quite understanding what's going on here. Python help thread? - XTOTHEL - 2011-03-14 I believe all you have to do is: c_sorted = c[:] and that will clone the list. Python help thread? - EarthAdept2 - 2011-03-14 Yes, exactly what I hoping for. Thanks a bunch! Python help thread? - JPTheMonkey - 2011-03-30 New problem: Making the program print a certain number of items per line. Unfortunately I deleted my program that did this, and threw out the print-out when I was cleaning drawers and binders. The program works except for printing the items. I need it to print all the elements of 'lst' but only 7 per line, forwards and backwards. Here it is: Code: lst = []Python help thread? - Fiel - 2011-03-30 http://docs.python.org/library/pprint.html Python help thread? - JPTheMonkey - 2011-03-30 Not understanding what they're saying. Just started Python in August as a school course. I dislike those database type things because they are hard for me to understand. Tried messing with the examples they had and am not getting what I need. Python help thread? - Alley - 2011-03-30 JPTheMonkey Wrote:Not understanding what they're saying. Just started Python in August as a school course. I dislike those database type things because they are hard for me to understand. Tried messing with the examples they had and am not getting what I need. I feel you. Half of what my teacher gives me is total crap that never works for his assignments. Python help thread? - Fiel - 2011-04-01 JPTheMonkey Wrote:Not understanding what they're saying. Just started Python in August as a school course. I dislike those database type things because they are hard for me to understand. Tried messing with the examples they had and am not getting what I need. Or you could do this: Code: STEPPING = 7Python help thread? - Nikkey - 2011-04-02 EarthAdept2 Wrote:They come out as both being sorted. I'm not quite understanding what's going on here. seq.sort() sorts the current sequence. seq.sorted() returns a sorted version of seq without modifying seq itself. Code: c = [1,5,6,3,2,10]Python help thread? - JPTheMonkey - 2011-04-06 Old thing, but my Pig Latin thing needs to do sentences (got that) and punctuation (don't got that). I used methods I could read based off of the response's methods. Fixed the list one, as well. Classmate pointed out eval which I'd entirely forgotten about which helped a lot: Code: count = 1As for the sentence, I have: Code: sent = raw_input("Enter the sentence you would like to have translated: ")What comes out with a punctuation mark: Code: This program translates a word entered by the user into Pig Latin.The last word is omitted entirely. I can't figure out where I should have it add the last word, either. Python help thread? - Alley - 2011-04-12 So, basically I have to return a string backwards. So if I input "Cookies are freaking good.", it has to return, ".doog gnikaerf era seikooC". Here's what I think has to be done, but it isn't working. Quote:def backwards_word(words): Python help thread? - XTOTHEL - 2011-04-12 don't know too much python...but I think you can try "index -= 1", instead of 0. or just "index--" also you want it to be "index = len(words)" and "while index <= 0" you actually don't need letter, just do "print words[index]" Code: def backwards_word(words):IDK HOW INDENTING WORKS, so figure that part out yourself. Python help thread? - JPTheMonkey - 2011-04-12 Code: words = "I am a cookie."This works, but with one extra space. Not sure how to get rid of that. Python help thread? - Fiel - 2011-04-12 Use [noparse] Code: , not [quote][/noparse] when inputting code.Or you could use some Python-fu and do this: Code: inputString = "Cookies are freaking good."@JPTheMonkey Do: sent.split(" ") Alternatively: Code: import rePython help thread? - Alley - 2011-04-13 None of that works. Closest is the revision XTOTHEL did. I think I had that earlier, it is giving the same output as I was getting originally before I started to tinker with it. I get the first letter of the input then the backwards input, but it is horizontal, then I get a traceback error. So it looks like this: Code: Word: crapPython help thread? - Fiel - 2011-04-13 Start with -1, not with 0 Code: word = 'crap' |