Posts
 
Reputation
Joined
Last Seen
0 Reputation Points
Unknown Quality Score

No one has voted on any posts yet. Votes from other community members are used to determine a member's reputation amongst their peers.

0 Endorsements
~11.1K People Reached
Favorite Forums
Favorite Tags
Member Avatar for pyprog

I was just wondering if there is a method or something in Java that, once a URL has been passed, can determine if a webpage under that URL was written in HTML, PHP, XML, and so on. I looked in URL and HTTPConnection classes but didn't find anything. Maybe missed …

Member Avatar for Taywin
0
76
Member Avatar for pyprog

I am wondering how to write a function that prints values of tree nodes from a root to a lowest child. If the tree looks like [CODE] 1 2 3 4 5 6 7 8[/CODE] then the output should be 1 3 6 8. My function is [CODE]def traverse(node): if …

0
79
Member Avatar for pyprog

I have the following class. I have tried many basic examples but I always get the same error. [CODE]class Factorial(object): def calculate(self, n): if n == 0: return 0 elif n == 1: return 1 else: return n * calculate(self, n - 1) if __name__ == "__main__": fact = Factorial() …

Member Avatar for jcao219
0
118
Member Avatar for pyprog

Let's say I want to create two classes Owner and Pet [CODE]class Owner(object): def __init__(first_name, last_name, address, phone): self.first_name = first_name self.last_name = last_name self.address = address self.phone = phone class Pet(object): def __init__(name, owner) self.name = name self.owner = Owner.__init__(first_name, last_name, address, phone)[/CODE] Did I pass the class Owner …

Member Avatar for pyprog
0
103
Member Avatar for pyprog

I want to remove all the 1's from the sublists so l becomes [[2], [2], [2]] but have trouble keeping track of indices. Can someone help out? [CODE]l = [[1, 2, 1],[1, 1, 2],[2, 1, 1]] i = 0 for element in l: while i < len(element): if element[i] == …

Member Avatar for vegaseat
0
137
Member Avatar for pyprog

[CODE]list1 = [[],[],[]] list2 = [[1,2,3],[4,5,6],[7,8,9]] i = 0 j = 0 k = 0 while i < len(list1): list1[i].append(list2[j][k]) i += 1 k += 1[/CODE] I want my output for list1 to be [[1,4,7],[2,5,8],[3,6,9]]. The problem is I don't know how to advance through the lists in list2. Can …

Member Avatar for arunbg
0
157
Member Avatar for pyprog

I am trying to write a program that prints every line of the file until a certain string is found. The file is a plain text file. I put the sample context at the top of the code. But the function gets stuck in an infinite loop. I don't want …

Member Avatar for IsharaComix
0
7K
Member Avatar for pyprog

If I have a string "knockknock", and use the string method replace [CODE]s = "knockknock" s = s.replace("knock", "bam") s "bambam"[/CODE] it replaces both occurences of the substring at once. Is it possible to replace each substring individually as in ("bamknock", "knockbam")?

Member Avatar for vegaseat
0
98
Member Avatar for pyprog

I have a file of the following format: a 1 a 2 a 3 b 4 b 5 b 6 c 7 c 8 c 9 Here is my code: [CODE]def file_to_dict(fname): f = open("file.txt") d = {} for line in f: columns = line.split(" ") letters = columns[0] numbers …

Member Avatar for pythopian
0
1K
Member Avatar for pyprog

I have a dictionary like {"a":["b", "c", "d"], "b":["h", "i", "j"], "c":["k", "l", "m"]. I need to write a function that returns True if a requested key has requested value. Also, if "a" has "b" and "b" has "h", "i", and "j", then "a" has "b", "c", "d", "h", "i", …

Member Avatar for masterofpuppets
0
129
Member Avatar for pyprog

Can I pass a string filename as a parameter to a function? For example, [CODE]def func("something.txt"):[/CODE] When I do this, it says that the syntax is invalid. Is there a proper way to do it or it is simply not done?

Member Avatar for pythopian
0
111
Member Avatar for pyprog

I have a file like this: a,z,1 b,y c,x,1 d,w,1 e,v f,u What I need to do is to create a dictionary that has the characters in the first column as keys and characters in the third column as values. The rest should be ignored, i.e. {a:1, c:1, d:1}. This …

Member Avatar for pythopian
0
128
Member Avatar for pyprog

Assume I have a file of the following format: a,1 b,2 c,3 d,4 Here is my code: [CODE]def junk(f): d1 = {} d2 = {} for line in f: columns = line.split(",") letters = columns[0] numbers = columns[1] d1[letters] = numbers d2[numbers] = letters return (d1, d2) def something(): print …

Member Avatar for vegaseat
0
159
Member Avatar for pyprog

Assume I have a file of the following format: a,1 b,2 c,3 d,4 Here is my code: [CODE] def junk(f): d1 = {} d2 = {} for line in f: columns = line.split(":") letters = columns[1] numbers = columns[2] d1[letters] = numbers d2[numbers] = letters return (d1, d2) def something(): …

Member Avatar for vegaseat
0
321
Member Avatar for pyprog

If I have a file that has a content of this kind: a,b c,d e,f g,h I need to make a list of the letters in the first column, i.e., [a, c, e, g]. I wrote some code which prints these letters but I don't know how to put them …

Member Avatar for snippsat
0
195
Member Avatar for pyprog

Hey, everyone. I know how to strip certain characters from a string using for loop. Can you give an example of how that can be done with the use of while loop?

Member Avatar for Gribouillis
0
102
Member Avatar for pyprog

If I have a string "Mary had a little lamb" and a list of strings such as ["Mary", "Bob", "Steve"] how to use a loop to search this string for items in the list?

Member Avatar for masterofpuppets
0
108
Member Avatar for pyprog

The following code should return the longest odd-length palindrome in a string centered at the index. So in a string 'asradarer' it should return 'radar'. Can you explain to me what the problem here is? [CODE]def get_odd_palindrome_at(word, index): num = 1 new_word = "" while index < len(word): if word[index …

Member Avatar for vegaseat
0
893