请帮我将这段代码转成python格式

python初学者,需要的一个模型是scala格式,如何转成python,请大家帮助。

// subsampling the words : refer to Google's word2vec NIPS paper to understand this
//
if (sample > 0)
sen = sen.filter(id => subSample(id) != -1)

val senLength = sen.size
for (senPosition <- 0 until senLength) {
  val currWord = sen(senPosition)

  //
  // dynamic window-size as in word2vec. 
  //
  val b =  rng.nextInt(window)
 // make the contexts
      //
      val contexts = new mutable.ArrayBuffer[Int]
      for (a <- b until window * 2 + 1 - b) if (a != window) {
        val c = senPosition - window + a
        if (c >= 0 && c < senLength)
          contexts += sen(c)

手写的,大概你参考下

if sample > 0:
  sen = filter(lambda id : subSample(id) != -1)
  senLength = sen.size
  for senPosition in range(senLength - 1):
    currWord = sen(senPosition)
    val b =  rng.nextInt(window)
    contexts = []
    for (a in range(b, window * 2 + 1 - b):
      if a != window):
        c = senPosition - window + a
      if c >= 0 and c < senLength:
        contexts.append(sen(c))