3,386 Posted Topics
Re: And if the num is 413, what your code does and what the request asks? | |
Re: 0 is smaller than any of your numbers in file, so you should initialize `minVal` to `inputArray[0]` and start for from `i=1`. | |
Re: You can basically treat the appearance of x as command 'add previous number to x-count' and any other not-number as 'add previous number to constant value'. Only thing is that if number was not there, you must default to one for x case, 0 for constant. | |
Re: The modules name is turtle (as is not C but pure Python). Try also to not use camelCase but words_with_underscores, if possible. See the [PEP8 paper](http://www.python.org/dev/peps/pep-0008/). Or you must download and install this non-standard module: http://www.cs.ucsb.edu/~pconrad/cs8/topics/cTurtle/ http://www.pythonworks.org/pycontext | |
Re: I would not use this code as base but think logic fresh, looks like machine translation of loops to recursion, yak :(! * What is the base case you know to sort? * How you reduce the size of problem to ultimately this base case by recursing? | |
Re: v = "min and max 0.00 1.50" print v.rsplit(' ',2)[-2:] "" Output: ['0.00', '1.50'] """ | |
Re: With Exceptions: [CODE]from __future__ import division, print_function def solve(v=None, u=None, a=None, t=None): try: v = u + a*t print('v') except TypeError: try: u = v - a*t print('u') except TypeError: try: a = (v-u) / t print('a') except TypeError: print('t') t = (v-u) / a assert v == u + … | |
Re: @nbaztec: Your code did not quite run and produce expected result, this was what did give it, after some debug: ~~~ import re garbled_text= '----3.82' pattern = r'(?P<data>[+\-]?(?:(?:\d+\.\d+)|\w+))|(?P<garbage>.)' g = '' for m in re.finditer(pattern, garbled_text): if m.group('data'): print m.group('data'), repr(g) # m.groupdict() will also work g = '' else: … | |
Re: [This](http://wiki.python.org/moin/EscapingXml) looks like what you need. | |
Re: We can carry a count with us as we move, this works for movesto(a,e, Dist) but crashes my GNU-Prolog for impossible case movesto(c,e), I do not know what should be changed: ~~~ /*-------------- connections between points --------------*/ link(a,b). link(b,c). link(b,d). link(d,e). /*-------------- logic carried out to connect the movements. --------------*/ … | |
Re: Start with very low starting value and update with each value that is bigger than current max. | |
Re: Do [decision tree](http://www.daniweb.com/members/nbaztec/758642/comments) and transform it to if statements after testing the tree with permutattions of 1,2,3,4 and 1,1,1,1 as values to sort. | |
Re: >better to swap the data, if this was for a real problem, not an exercise Yes and if you swap data, you must still be quite sure that there is not any other pointers existing to the nodes or you have nightmare to debug. I would think so, no real … | |
Re: I am not expert in using re in Python, but could this example I made be relevant? ~~~ import sys import re pattern = re.compile(r'\w+') # process the text of this program as input with open('./file.txt') as inp: text = inp.read() match = re.findall(pattern, text) not_match = re.split(pattern, text) print(match) … | |
Re: See: http://www.daniweb.com/software-development/computer-science/threads/324685/a-brief-introduction-to-big-o-notation-the-big-oh-notation | |
Re: >Because Daniweb now sucks for pasting code. Good job Daniweb. You can put ~~~ before and after code in separate lines and surround the code with empty lines before and after, then you do not need to indent it. | |
Re: Let me recapitulate simply, how I understand the Dani's plan: 1. Old situation with hierarchy of forums was pain in sitting parts to keep up to date and to choose in the correct subforum. 2. Solution of Dani is simply to remove the subforums and encourage to replace the functionality … ![]() | |
Re: [Picking piece of string between separators](http://www.daniweb.com/software-development/python/code/289548/picking-piece-of-string-between-separators) | |
Re: What of [these hints](http://lmgtfy.com/?q=DJANGO_SETTINGS_MODULE+is+undefined) you tried? | |
Re: I would think that good logic is to find a pair of same values and remove them, what is left is odd number values. Making new sequence could be safer to avoid problems in iterating changing sequence. | |
Re: Can not test with your code as we have not definition of the myriad variables in your dictionary as values or keys, and there is some comma missing but it should be something like: `print({key:d[key].keys() for key in d})` If I put strings instead of your variables, I get: ~~~ … | |
Re: You might find some easy enough problems in [Rosetta code](http://rosettacode.org/wiki/Rosetta_Code) You can do your own solution and see the previous Java answer, and compare them. | |
Re: print(['e' if letter == 'e' else '-' for letter in 'elephant']) '''Output: ['e', '-', 'e', '-', '-', '-', '-', '-'] ''' Your code is not tested to work and does not belong to code snippets. | |
Re: As printed binary number it is one and 60000 zeroes. | |
Re: You are looking for wrong tool, you should use http://docs.python.org/library/optparse.html or preferably the new http://docs.python.org/library/argparse.html#module-argparse for parameter aquisition. That said it is easy to just iterate over the parameters and check which starts right way: ~~~ >>> print next(p for p in cmd.split() if p.startswith('--date')) --date=20120323 ~~~ | |
Re: You are messing your changes for help enough, by posting here in Community Feedback. How about messing with a good manual? | |
Re: I do not understand, post your Python code to see what you mean. (Paste-paint-push **Code**) | |
Here is my take as code tag police in new era of Daniweb: http://www.daniweb.com/software-development/python/threads/418619/generate-page-using-python Reposted here: Could you repost with new code markup, which is indention by at least 4 spaces, after empty line, so you could do in your python editor: ctrl-A, indent, ctrl-C, undo (or close without saving) … | |
Re: The Edit Post does post edited version, but it need refresh of the page before starting to edit. I have suggested that it should say something else like 'Update the Post' in Community Feedback forum. We unfortunately are left sometime on our own, as the staff is busy to get … | |
Re: Could you repost with new code markup, which is indention by at least 4 spaces, after empty line, so you could do in your python editor: ctrl-A, indent, ctrl-C, undo (or close without saving) and paste it to your post. Or make empty line, paste code, select it by mouse … | |
Re: You are overcomplicating things, pseudocode: empty sequence has 0 even numbers, other sequences have (1 if first number even else 0 + number of even in rest of sequence) even values | |
Re: Even there usually is usually in beginning only simulator for new processor and cross compiler for it running in differfent developing environment if new system is not backwards com | |
Re: For example [url]http://www.tutorialspoint.com/python/python_functions.htm[/url] has concise explanation of functions with examples. | |
| |
Re: Looks like you are after the anagrams: http://www.daniweb.com/software-development/python/code/285434/super-simple-one-word-anagrams | |
Re: Looks like the staff is aware of it and they will return in due course: http://www.daniweb.com/community-center/daniweb-community-feedback/threads/418548/tutorials-listing-/1#post1784617 | |
Re: Nice way to get formatted input is to use generator function with for: def get_leases(fn): with open(fn) as lease_file: block = '' for line in lease_file: if block and line.startswith('lease'): yield block block = '' block += line if block: yield block for no, lease in enumerate(get_leases('lease.txt'), 1): print('lease {}:\n{}'.format(no, … | |
Re: Do you have some desing plans about the style of information presented? If it is only table, it is not so difficult to only generate the HTML and use [Python for CGI]( http://www.penzilla.net/tutorials/python/cgi/ )). | |
Re: You are not returning the value for else branch, the newlist is not really needed, you can check with tail of L. And in real life you would do: [CODE] def has_repeats(L): return len(set(L)) != len(L)[/CODE] with hashable item sequence (no sublists). My solution: [CODE]def has_repeats(L): if len(L) < 2: … | |
Re: Post the code you have, sample input data for the function you are strugling with and current output including the full error messages and desired output. Do not forget to push the `[CODE]` before pasting. | |
Re: Compare with: [URL="http://rosettacode.org/wiki/Hailstone_sequence#Python"]http://rosettacode.org/wiki/Hailstone_sequence#Python[/URL] | |
Re: Your code is not indented properly, no, that was just problem with your long lines in mobile screen, I will check it up. Finally the indention was off, you are mixing tabs with spaces, also you are naming functions with Capitalized names, which look like object names due to Python … | |
Re: [CODE]>>> import numpy >>> m = numpy.array([4, 6, 8]) >>> m array([4, 6, 8]) >>> print m[-1]+16*m[-2]+16**2*m[-3] 1128 >>> sum(m*[16**2, 16, 1]) 1128 >>> bin(1128) '0b10001101000' >>> [/CODE] | |
| |
Re: Is it your or my homework? [url]http://docs.python.org/tutorial/introduction.html#first-steps-towards-programming[/url] | |
Re: Don't know the structure of your data, but the previous example other way: [CODE]data = "abacc" some_dict={key:[k for k in data if k == key] for key in set(data)} print some_dict [/CODE] | |
Re: How remarkably similar code compared to [url]http://www.reddit.com/r/Python/comments/qm40j/whats_wrong_with_my_code_python/[/url] | |
Re: Two dimensional array as List of list is fine, only problem in it is that you must not use * operation to produce the lines from values, as that produces reference to same value. You seem to be actually planning three dimensional array as in your example you have list … |
The End.