小编row*_*ana的帖子

TypeError:str对象不是迭代器

我有一个由单词组成的文件,每行一个单词.该文件如下所示:

aaa
bob
fff
err
ddd
fff
err
Run Code Online (Sandbox Code Playgroud)

我想计算一对一出现的单词的频率.

例如,

aaa,bob: 1
bob,fff:1
fff,err:2
Run Code Online (Sandbox Code Playgroud)

等等.我试过这个

f=open(file,'r')
content=f.readlines()
f.close()
dic={}
it=iter(content)
for line in content:
    print line, next(line);
    dic.update({[line,next(line)]: 1})
Run Code Online (Sandbox Code Playgroud)

我收到了错误:

TypeError: str object is not an iterator
Run Code Online (Sandbox Code Playgroud)

然后我尝试使用迭代器:

it=iter(content)
for x in it:
    print x, next(x);
Run Code Online (Sandbox Code Playgroud)

再次遇到同样的错误.请帮忙!

python dictionary iterator generator

8
推荐指数
2
解决办法
5441
查看次数

将文件上传到github中的分支

我知道有关于此的数百个教程,但我无法确定从哪里开始.我正在使用MAC并且运行Ubuntu 14.04的远程系统.我想要做的是将文件夹上传到我的组织的github存储库.已经存在一个repo,我想创建一个分支并在该分支中上传我的文件和文件夹.

我试过了

git branch branch_name
git checkout branch_name
Run Code Online (Sandbox Code Playgroud)

但是分支机构不会显示在网页上.我也试过从网页创建一个分支,但我不知道如何上传文件.我也不确定如何实际导航到我要上传的存储库.

请告诉我如何做到这一点.

谢谢!

git github

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

在Python中查找数组中整数出现次数

我见过这个这个.我想知道我是否可以在不使用像集合这样的库的情况下完成它,但是使用简单的循环结构.我可以用Python做到这一点吗?

void printRepeating(int arr[], int size)
{
  int *count = (int *)calloc(sizeof(int), (size - 2));
  int i;

  printf(" Repeating elements are ");
  for(i = 0; i < size; i++)
  {  
    if(count[arr[i]] == 1)
      printf(" %d ", arr[i]);
    else
     count[arr[i]]++;
  }    
} 
Run Code Online (Sandbox Code Playgroud)

我试过这样做 -

a=[1,2,3,2,4,3,1,7,4,3];
b=[];
for i in a:
        b[i]=b[i]+1;
Run Code Online (Sandbox Code Playgroud)

但我明白了

IndexError: list index out of range
Run Code Online (Sandbox Code Playgroud)

有办法解决吗?

python list

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

标签 统计

python ×2

dictionary ×1

generator ×1

git ×1

github ×1

iterator ×1

list ×1