我想将成对值(列、FILTER)列表加入到 URL 字符串中。
样本:$filter=包含(column1%2C%27FILTER1%27)+和+包含(column2%2C%27FILTER2%27)+and+包含(column3...
filter_lists = [['level', 'FIRST'], ['name', 'OFFICE'], ['number', 'FIVE']]
filter1 = f"contains({filter_lists[0][0]}%2C%27{filter_lists[0][1]}%27)"
filter_rest = [[f"+and+contains({item}%2C%27" for item in filter_lists[1:]] for subitem in filter_lists[0]][0]
filter_all = "".join(filter_rest)
url_str = f"$filter={filter1}{filter_all}"
url_str 返回: $filter=包含(level%2C%27FIRST%27)+and+contains(['name', 'OFFICE']%2C%27+and+contains(['number', 'FIVE']%2C%27
所需字符串: $filter=包含(级别%2C%27FIRST%27)+和+包含(名称%2C%27OFFICE%27)+和+包含(数量%2C%27FIVE%27)
是否有更简单的方法而不是将列和过滤器存储在列表[list]中?
filter_lists = [['level', 'FIRST'], ['name', 'OFFICE'], ['number', 'FIVE']]
filter1 = f"contains({filter_lists[0][0]}%2C%27{filter_lists[0][1]}%27)"
filter_rest = [[f"+and+contains({item[0]}%2C%27{item[1]}%27)" for item in filter_lists[1:]] for subitem in filter_lists[0]][0]
filter_all = "".join(filter_rest)
url_str = f"$filter={filter1}{filter_all}"
返回: $filter=包含(级别%2C%27FIRST%27)+和+包含(名称%2C%27OFFICE%27)+和+包含(数量%2C%27FIVE%27)