Python - 检查部分类似的字符串

时间:2018-02-13 14:17:44

标签: python-3.x

我想问一下我的表格中有数据:

"Data":[
   {
      "TradePairId":1261,
      "Label":"$$$/BTC",
      "AskPrice":0.00000038,
      "BidPrice":0.00000036,
      "Low":0.00000034,
      "High":0.00000038,
      "Volume":245611.54493283,
      "LastPrice":0.00000038,
      "BuyVolume":61190230.39331733,
      "SellVolume":10434778.71081393,
      "Change":8.57,
      "Open":0.00000035,
      "Close":0.00000038,
      "BaseVolume":0.08787847,
      "BuyBaseVolume":1.69560859,
      "SellBaseVolume":154560284.03335398
   },
   {
      "TradePairId":1263,
      "Label":"$$$/DOGE",
      "AskPrice":0.80000000,
      "BidPrice":0.50000072,
      "Low":0.50001005,
      "High":0.50001005,
      "Volume":0.0,
      "LastPrice":0.50001005,
      "BuyVolume":784338945.85694635,
      "SellVolume":199171.81421817,
      "Change":0.0,
      "Open":0.50001005,
      "Close":0.50001005,
      "BaseVolume":0.0,
      "BuyBaseVolume":23733.89175522,
      "SellBaseVolume":27405341.85800020
   },
   {
      "TradePairId":1262,
      "Label":"$$$/LTC",
      "AskPrice":0.00002895,
      "BidPrice":0.00001960,
      "Low":0.00002200,
      "High":0.00002200,
      "Volume":0.0,
      "LastPrice":0.00002200,
      "BuyVolume":539276.15940958,
      "SellVolume":567637.85244947,
      "Change":0.0,
      "Open":0.00002200,
      "Close":0.00002200,
      "BaseVolume":0.0,
      "BuyBaseVolume":0.37966392,
      "SellBaseVolume":1313.13194663
   },
   {
      "TradePairId":5181,
      "Label":"1337/BTC",
      "AskPrice":0.00000005,
      "BidPrice":0.00000004,
      "Low":0.00000004,
      "High":0.00000005,
      "Volume":18362406.71548798,
      "LastPrice":0.00000004,
      "BuyVolume":796558248.24106350,
      "SellVolume":705718844.66611060,
      "Change":0.0,
      "Open":0.00000004,
      "Close":0.00000004,
      "BaseVolume":0.79514855,
      "BuyBaseVolume":14.43608460,
      "SellBaseVolume":302726202.23174182
   },
   {
      "TradePairId":3944,
      "Label":"1337/DOGE",
      "AskPrice":0.05296980,
      "BidPrice":0.03760004,
      "Low":0.05000000,
      "High":0.05000000,
      "Volume":0.0,
      "LastPrice":0.05000000,
      "BuyVolume":1787712464.11137154,
      "SellVolume":11244356.11156200,
      "Change":0.0,
      "Open":0.05000000,
      "Close":0.05000000,
      "BaseVolume":0.0,
      "BuyBaseVolume":266027.93858629,
      "SellBaseVolume":872284118.43164375
   },
   {
      "TradePairId":3943,
      "Label":"1337/LTC",
      "AskPrice":0.00000260,
      "BidPrice":0.00000152,
      "Low":0.00000260,
      "High":0.00000260,
      "Volume":0.0,
      "LastPrice":0.00000260,
      "BuyVolume":74947197.56942268,
      "SellVolume":36196890.65558968,
      "Change":0.0,
      "Open":0.00000260,
      "Close":0.00000260,
      "BaseVolume":0.0,
      "BuyBaseVolume":26.50542485,
      "SellBaseVolume":2519903395.27105924
   },
   {
      "TradePairId":5313,
      "Label":"21M/BTC",
      "AskPrice":0.00004986,
      "BidPrice":0.00004420,
      "Low":0.00004433,
      "High":0.00005693,
      "Volume":10556.77600080,
      "LastPrice":0.00004500,
      "BuyVolume":1226185.96344030,
      "SellVolume":177194.04092096,
      "Change":-20.96,
      "Open":0.00005693,
      "Close":0.00004500,
      "BaseVolume":0.50858713,
      "BuyBaseVolume":0.85099172,
      "SellBaseVolume":25669.63041795
   },
   ....
]

我想从这个列表中获取这些索引的数据,其中关键字' Label'中的前3个字符是相同的,对于' /&#39后面的接下来的三个字符串;应该只是" BTC"," USDT"或" NZDT"

例如:1st index =" Label":" $$$ / BTC"和第二个指数="标签":" $$$ / USDT"所以在关键字"标签"的前三个字母的基础上即" $$$"我想获取1个索引和2个索引的数据,因为这些索引中的字母相同而第二对字母也是" BTC"和" USDT"无论是" $$$"不适用于" NZDT"。

我知道我不清楚,但这是否可能, 提前致谢

1 个答案:

答案 0 :(得分:1)

据我所知,python中的re模块(正则表达式)可以满足您的要求。使用import re导入它并研究其compile()函数。您还可以查看this