django - 拆分此列表的所有三个属性
问题描述
[8352] Marilyn Hudson - 16000 Views
这是我从 FacebookAdsAPI 获得的实例,我一直在尝试将单独的列表分别分成 3 个属性。
我用过
client.split("]")[1]
但它给了我Marilyn Hudson - 16000 Views
。我怎样才能分别获得所有三个属性?预期产出 -
id >> 8352
name >> Marilyn Hudson
impressions >> 16000
TIA
解决方案
如果我理解正确,
In [1912]: client
Out[1912]: '[8352] Marilyn Hudson - 16000 Views'
In [1930]: new_list.append(re.findall(r'\d+', client.split('-')[0])[0])
In [1931]: new_list.append(client.split('-')[0].split('] ')[1].strip())
In [1932]: new_list.append(client.split('-')[1].strip())
In [1933]: new_list
Out[1933]: ['8352', 'Marilyn Hudson', '16000 Views']
让我知道这是否有帮助。
推荐阅读
- angular - 自 Angular 6.0 以来不推荐使用 Angular Header/Http/RequestOptions,如何将它们更新为 Angular 8.0?
- python - 如何使用 for 循环遍历字典列表、选择键并将值附加到新列表
- python - 如何创建一个空的蓝色图像?
- sapb1 - 如何使用 SAP B1 SDK 在日期字段中显示日期?
- javascript - Javascript参数忽略
- javascript - 为什么附加到引导导航栏时有 NaN 而不是变量?
- r - 在R中从下到上提取相似的值
- git - 有没有办法克隆特定 git 分支的标签?
- javascript - 绝对定位的 div 不滚动;当其他内容滚动时保持固定在屏幕上
- oracle - 我可以为 SqlPlus 中的值列表定义一个变量吗