我有一个以下格式的嵌套列表:
[['john'],['jack','john','mary'],['howard','john'],['jude']...]
Run Code Online (Sandbox Code Playgroud)
我想找到嵌套列表中出现的前 3 或 5 个 john 索引(因为列表真的很长)并返回索引,例如: (0,0),(1,1),(2,1) 或采用任何建议的格式。
我对嵌套列表相当陌生。任何帮助将非常感激。
又是我.这是一个与我正在做的项目相关的代码,称为Twitter数据上的情感分析.以下代码主要用于显示正负推文的数量,我在下面给出了错误.
from pyspark import SparkConf, SparkContext
from pyspark.streaming import StreamingContext
from pyspark.streaming.kafka import KafkaUtils
import operator
import numpy as np
import matplotlib.pyplot as plt
def main():
conf = SparkConf().setMaster("local[2]").setAppName("Streamer")
sc = SparkContext(conf=conf)
# Creating a streaming context with batch interval of 10 sec
ssc = StreamingContext(sc, 10)
ssc.checkpoint("checkpoint")
pwords = load_wordlist("positive.txt")
nwords = load_wordlist("negative.txt")
counts = stream(ssc, pwords, nwords, 100)
make_plot(counts)
def make_plot(counts):
"""
This function plots the counts of positive and negative words for each timestep.
"""
positiveCounts = …Run Code Online (Sandbox Code Playgroud)