由MBA Skool团队发表,最后更新:2021年1月2日什么是心理分割?心理细分是一种市场细分策略,根据心理、信念、个性、特征、生活方式、态度、原因等对整个市场进行细分。心理细分有助于根据人们的思维方式以及他们想要的生活方式,从生活方式、地位等方面来识别人们。这种细分方法关注的是客户的心理,公司可以在营销活动中关注这些心理。心理分割更多地植根于心理学领域,而不是传统的年龄、收入等分割变量。
发布于 2021-02-06 05:47:37
你可以试试这个
text="pie\n hotdogs\n noodles\n cheese\n..."
rows=text.split("\n")
result = dict((j,i+1) for i,j in enumerate(rows))
print(result)更新:如果你想保存所有的重复,你不能使用dict。但是您可以使用这样的元组列表
text="pie\n hotdogs\n noodles\n cheese\n... \n pie"
rows=text.split("\n")
result = [(j, i+1) for i,j in enumerate(rows)]
print(result)发布于 2021-02-06 05:53:22
file1 = open('nameoffile.txt', 'r')
dictionary={}
for index, line in enumerate(file1, start=1):
dictionary[line.strip()] = index
file1.close()
print(dictionary)发布于 2021-02-06 05:55:20
我想像这样的东西会适合你的目的:
# read from file
input_path = "input.txt"
with open(input_path, "r") as file:
text = file.read()
your_dict = {}
for line_idx, line_text in enumerate(text.split('\n')):
your_dict[line_text] = line_idx+1
# your_dict is what you want但是,请注意,重复行将只报告最新出现的索引。如果要存储所有匹配项,则应对每行文本使用索引列表:
from collections import defaultdict
your_dict = defaultdict(list)
for line_idx, line_text in enumerate(text.split('\n')):
your_dict[line_text].append(line_idx+1)
# now each line will give you a list of indices in ascending orderhttps://stackoverflow.com/questions/66071009
复制相似问题