简体   繁体   English

在python中索引数量列表元素

[英]indexing quantity list element in python

I have a text file where I have this information:我有一个文本文件,其中包含以下信息:

BRIEF DESCRIPTION A herbaceous, upright, often much branched, slightly woody plant, up to 2-4 m in height, with spiny pubescence, large yellow flowers, and fruits which at maturity dry to a longitudinally dehiscent capsule, 25 cm long or more.简述一种草本、直立、常分枝、微木本植物,高达2-4 m,具多刺的短柔毛,大的黄色花,果实成熟时干燥成纵向开裂的蒴果,长25 cm或更长。 USES The young immature fruits are eaten fresh, cooked or fried as vegetables and the can be frozen, canned or dried.用途 未成熟的幼果可鲜食、煮熟或油炸作为蔬菜,可冷冻、罐装或晒干。 Fruits have medicinal properties.水果具有药用价值。 Ripe seeds contain 20% edible oil and they can be used as a substitute for coffee.成熟的种子含有 20% 的食用油,可作为咖啡的替代品。 In India, mucilage from the roots and stems has industrial value for clarifying sugarcane juice in gur manufacture.在印度,根和茎的粘液对于在 gur 制造中澄清甘蔗汁具有工业价值。 Dried okra powder is used in salad dressings, ice creams, cheese spreads, and confectionery.干秋葵粉用于沙拉酱、冰淇淋、奶酪酱和糖果。 The stems provide a fiber of inferior quality.茎提供劣质纤维。 GROWING PERIOD Annual.生长期 每年。 May require 50-90 days to first harvest and the harvest period may continue up to 180 days.第一次收获可能需要 50-90 天,收获期可能持续长达 180 天。 COMMON NAMES Okra, Ochro, Lady's Finger, Gumbo, Gombo, Cantarela, Quingombo, Rosenapfel, Bindi, Bhindee, Bhindi, Mesta, Vendakai, Kachang bendi, Kachang lender, Sayur bendi, Kachieb, Grajee-ap morn, You-padi, Ch'aan K'e, Tsau Kw'ai, Ila, Ilasha, Ilashodo, Quimbambo, Kopi arab, Khua ngwang, Krachiap mon, Dau bap.常见名称秋葵、Ochro、女士手指、秋葵、Gombo、Cantarela、Quingombo、Rosenapfel、Bindi、Bhindee、Bhindi、Mesta、Vendakai、Kachang bendi、Kachang 贷方、Sayur bendi、Kachieb、Grajee-ap morn、You-padi、Ch 'aan K'e, Tsau Kw'ai, Ila, Ilasha, Ilashodo, Quimbambo, Kopi arab, Khua ngwang, Krachiap mon, Dau bap。 FURTHER INF Scientific synonym: Hibiscus esculentus.更多信息 科学同义词:Hibiscus esculentus。 Okra originated in South-East Asia.秋葵起源于东南亚。 Most varieties grow well in the lowland humid tropics up to elevations of 1000 m.大多数品种在海拔1000米以下的低地湿润热带地区生长良好。 Adapted to moderate to high humidity.适应中高湿度。 Okra is a short-day plant, but it has a wide geographic distribution, up to latitudes 35-40°S and N. Yields of green pods are often low, about 2-4 t/ha owing to extreme growing conditiuons, but up to 10-40 t/ha may be produced.秋葵是一种短日照植物,但它的地理分布很广,最高可达南纬 35-40°和北纬。由于极端生长条件,绿豆荚的产量通常较低,约为 2-4 吨/公顷,但可生产 10-40 吨/公顷。

I am using the library quantulum which extracts all the measurement automatically.我正在使用自动提取所有测量值的库 quantulum。

BriefDescription is a variable that contains text BriefDescription 是一个包含文本的变量
The QuantDescription stores all the quantity from the BriefDescription QuantDescription 存储来自 BriefDescription 的所有数量
I need to get the values that are "metre" string in the second parameter of the quantity tuple我需要在数量元组的第二个参数中获取“米”字符串的值
I need to figure out how to get the index of the tuples我需要弄清楚如何获取元组的索引

    quantsDescription = parser.parse(BriefDescription)
    quantsUses = parser.parse(Uses)
    quantsPeriod = parser.parse(GrowingPeriod)
    print 'BriefDescription Quant:'
    print quantsDescription
    print 'Uses Quant:' 
    print quantsUses
    print 'GrowingPeriod Quant:'
    print quantsPeriod
    for i in quantsDescription:
        print type(i[1])  # indexing the second element of the tuple?

This the output list for quantsDescription:这是 quantsDescription 的输出列表:
[Quantity(2, "metre"), Quantity(4, "metre"), Quantity(25, "centimetre")] [数量(2,“米”),数量(4,“米”),数量(25,“厘米”)]

print quantsDescription[0].unit.name # to get the unit's quantity
print quantsDescription[0].value # to get the amount of the quantity

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM