Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
ProbEnthought Canopylems with
#1
I am having problems with Enthought Canopy, whatever my code I get error e.g. for this program I get
return [l]
^
IndentationError: unexpected indent
although this is a program already published:
def perm(l):
        # Compute the list of all permutations of l
    if len(l) == 1: 
        print len
                  return [l]
    r = [1]
    print r
    for i in range(len(l)):
             s = l[:i] + l[i+1:]
             p = perm(s)
             for x in p:
              r.append(l[i:i+1] + x)
  
    return r
Reply
#2
Some observations:

- you (probably) use Python 2. I suggest to switch to Python 3. Python 2 is EOL at the end of this year

- as stated in error - there should be no intent. Return statement must be on same level as previous row (row #4).

- you have statement 'print len', assuming that this is Python 2 it works but output will be <built-in function len>. Is it what you want?

- Python intentation is 4 spaces

- if you need permutations then have a look at built-in module itertools and function defined there itertools.permutations(). There is code provided how permutations function (roughly) works.
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply
#3
Thanks! Works now.
Reply
#4
This also does not work - Syntax error. Kindly help.:
soup = BeautifulSoup(xml, 'html.parser')
lat = soup.find('latitude')
<lat>
 <latitude>1.123123</latitude>
</lat>
print((lat.text))
#1.123123
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020