小编use*_*929的帖子

队列类,出队和入队?蟒蛇

所以我有这个问题,它说创建一个类队列并使该方法出列并入队

这就是我到目前为止,有人能引导我走上正轨吗?

class queue:
      def __init__(self,queue):
            self.queue = []
      def dequeue(self):
            if len(queue) > 0:
                  e = queue[0]
                  queue = list[1:len(queue)]
            else:
                  return "There are no elements to remove"
      def enqueue(self,element):
            queue.insert([-1], element)
Run Code Online (Sandbox Code Playgroud)

python queue methods class

4
推荐指数
1
解决办法
2万
查看次数

Python错误:"找不到指定的路径"

import os
import random

os.chdir("C:\Users\Mainuser\Desktop\Lab6")

#Am i supposed to have a os.chdir? 
# I think this is what's giving the error
#how do i fix this? 

def getDictionary():
      result = []
      f = open("pocket-dic.txt","r")
      for line in f:
            result = result + [ line.strip() ];
      return result

def makeText(dict, words=50):
      length = len(dict)
      for i in range(words):
            num = random.randrange(0,length)
            words = dict[num]
            print word,
            if (i+1) % 7 == 0:
                  print 
Run Code Online (Sandbox Code Playgroud)

Python给我一个错误,说它无法找到指定的路径,当我在桌面上清楚地有一个带有该名称的文件夹时.它可能是os.chidr ?? 我究竟做错了什么?

python random text path

3
推荐指数
1
解决办法
2万
查看次数

'builtin_function_or_method'对象不可订阅

def binary_search(li, targetValue):
    low, high = 0, len[li] #error on this line
    while low <= high:
        mid = (high - low)/2
        if li[mid] == targetValue:
             return "we found it!"
        elif li[mid] > targetValue:
             low = mid - 1;
        elif li[mid] < targetValue:
             high = mid + 1;
    print "search failure "
Run Code Online (Sandbox Code Playgroud)

刚刚发布了这个问题,但我的代码仍然不起作用?

python algorithm

3
推荐指数
2
解决办法
3万
查看次数

琐碎间距错误,python?

甚至问这个我感到很尴尬,但是因为某种原因python让我的错误给了我"l"

    def binary_search(l, targetValue):
          low = 0, high = len(array)
          while low <= high:
                mid = (high - low)/2
                if l[mid] == targetValue:
                     return "we found it!"
                elif l[mid] > targetValue:
                     low = mid - 1;
                else        l[mid] < targetValue: #this line seems to be the problem
                     high = mid + 1;
          print "search failure :( "
Run Code Online (Sandbox Code Playgroud)

python binary

0
推荐指数
1
解决办法
88
查看次数

标签 统计

python ×4

algorithm ×1

binary ×1

class ×1

methods ×1

path ×1

queue ×1

random ×1

text ×1