logo
down
shadow

indexing a list where there is no match in python


indexing a list where there is no match in python

By : user2955011
Date : November 22 2020, 10:33 AM
Hope that helps If I got this right, your mylist2 is kinda used as a dictionary. Why not just make it one:
code :
mylist1 = [[u'AAA', None, u'111' ,u'1/1/2015'], [u'BBB', None, u'222' ,u'1/1/2012'], [u'CCC', None, u'333' ,u'1/1/2012']]
mylist2 = [(u'111', u'1/1/2011'), (u'333', u'2013-11-10'), (u'444', u'1/1/2017')]
# assuming, you are not responsible for the form of mylist2,
# we will change it into a dictionary here:
mydict = dict(mylist2)   # easy :)
for elem_list in mylist1:
    elem_list[3] = min(elem_list[3], mydict.get(elem_list[2], elem_list[3]))


Share : facebook icon twitter icon
Python: Compare list of strings to list of tuples, and create a new list based on match or no match

Python: Compare list of strings to list of tuples, and create a new list based on match or no match


By : Absorption
Date : March 29 2020, 07:55 AM
hope this fix your issue I have a list of strings a, and a list of tuples b where: , EDIT :
Since you say -
code :
for source_dest_statement in source_dest_statements:
    amended_source_dest_statements.append(source_dest_statement)
    for i,j in in source_dest_tuple:
        if j in amended_source_dest_statements[-1]:
            amended_source_dest_statements[-1]   = re.sub(j,i,amended_source_dest_statements[-1])
>>> import re
>>> a=['from src1 to dest2','from src3 to dest4','from src5 to dest6']
>>> b=[['destb','dest2'],['destd','loc4'],['destf','dest6'],['desth','dest8']]
>>> result = []
>>> for x in a:
...     result.append(x)
...     for i,j in b:
...             if j in result[-1]:
...                     result[-1] = re.sub(j,i,result[-1])
...
>>> result
['from src1 to destb', 'from src3 to dest4', 'from src5 to destf']
for source_dest_statement in source_dest_statements:
    for i,j in in source_dest_tuple:
        if j in source_dest_statement:
            amended_source_dest_statements.append(re.sub(j,i,source_dest_statement))
    else:
        amended_source_dest_statements.append(source_dest_statement)
>>> a=['from src1 to dest2','from src3 to dest4','from src5 to dst6']
>>> b=[['dest2','destb'],['dest4','locd'],['dest6','destf'],['dest8','desth']]
>>> result = []
>>> for x in a:
...     for i,j in b:
...         if i in x:
...             result.append(re.sub(i,j,x))
...             break
...     else:
...         result.append(x)
...
>>> result
['from src1 to destb', 'from src3 to locd', 'from src5 to dst6']
Python equivalence of R's match() for indexing

Python equivalence of R's match() for indexing


By : Yash Singh
Date : March 29 2020, 07:55 AM
hop of those help? You can use first drop_duplicates and then boolean indexing with isin or merge.
Python counts from 0, so for same output add 1.
code :
A = pd.DataFrame({'c':['a','b']})
B = pd.DataFrame({'c':['c','c','b','b','c','b','a','a']})


B = B.drop_duplicates('c')
print (B)
   c
0  c
2  b
6  a

print (B[B.c.isin(A.c)])
   c
2  b
6  a

print (B[B.c.isin(A.c)].index)
Int64Index([2, 6], dtype='int64')
print (pd.merge(B.reset_index(), A))
   index  c
0      2  b
1      6  a

print (pd.merge(B.reset_index(), A)['index'])
0    2
1    6
Name: index, dtype: int64
error indexing a list within a list to create database columns sqlite3 python

error indexing a list within a list to create database columns sqlite3 python


By : Jeffrey Blechman
Date : March 29 2020, 07:55 AM
should help you out Your code works fine. Did you try print(columns) command ?
here is what I am getting
python: Add list elements based on original indexing (while updating list)

python: Add list elements based on original indexing (while updating list)


By : Geoff Poore
Date : March 29 2020, 07:55 AM
I hope this helps . Based on @r.user.05apr's very good idea to simply step through the whole input string char by char, I'd like to add a possibility to generalize this for an arbitrary long start_end-list:
code :
s = 'ABCDEFGHIJKL'
res = list()
for nr, sub in enumerate(s):
    res.append(sub)
    try:
        i = [nr in x for x in start_end].index(True)
        res.append('-(c' + str(i) + ')-')
    except:
        pass
res = ''.join(res)        
print(res)    
# AB-(c0)-C-(c1)-D-(c0)-E-(c1)-F-(c2)-G-(c2)-HIJK
Indexing a PDF as list of data frames based on regex pattern match

Indexing a PDF as list of data frames based on regex pattern match


By : Fabio
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , In extracting information from a pdf using tabulizer and pdftools, I sometimes would like to index a large list of df based on a regex pattern match. , We may use
code :
getIdx <- function(pattern, l)
  l %>% map_lgl(~ any(unlist(map(.x, grepl, pattern = pattern))))

getIdx("pension", my_list)
# [1]  TRUE FALSE

my_list[getIdx("pension", my_list)]
# [[1]]
#       yes
# 1 pension
Related Posts Related Posts :
  • pretty printing numpy ndarrays using unicode characters
  • Frequent pattern mining in Python
  • How can I make a set of functions that can be used synchronously as well as asynchronously?
  • Convert one dice roll to two dice roll
  • count occourrence in a list
  • Writing an If condition to filter out the first word
  • to read file and compare column in python
  • Install python-numpy in the Virtualenv environment
  • `.select_by_visible_text()` is failed to select element?
  • Unable to send data multiple requests in a single connection — socket error
  • Pandas HDFStore unload dataframe from memory
  • Creating a custom admin view
  • How do you get the user role of the currently logged in user in Ckan?
  • Speed up Numpy Meshgrid Command
  • Python error - name lengths
  • appending text to a global variable
  • Python Mistake - Number of letters in name
  • Searching for a sequence in a text
  • Testing logging output with pytest
  • How do I change my default working directory for Python (Anaconda) on VSCode?
  • .lower() for x in list, not working, but works in another scenario
  • Program gives error "List indices must not be string"
  • pyqt: Memory Usage
  • Confused about classes in Learn Python the Hard Way ex43?
  • Extracting unrecognized information from many CSV files
  • How do I connect to Postgresql server from Python?
  • Append rows to a pandas DataFrame without making a new copy
  • Scrapy: Importing a package from the project that's not in the same directory
  • launching Excel application using Python to view the CSV file , but CSV file is opening in read mode and cant view the d
  • Making a list in user-defined functions
  • Pyserial microcontroller to host communication
  • Plotting a line in between subplots
  • function not returning value. Error "NameError: name 'urlss' is not defined"
  • How to perform cartesian product with Tensorflow?
  • Multiple independent random number streams from single seed
  • I Need a simple and short python3 code that count secounds in a background process
  • No module named constants
  • from django 1.4 to django 1.5- argument 'verify_exists' what s replacement?
  • Slash replacement inside a raw string
  • Reordering columns/rows of a pivot_table?
  • MySQLdb.cursors.Cursor.execute does not work
  • Python module being reimported when imported at different places
  • Is the Session object from Python's Requests library thread safe?
  • Python Regex: Finding First and Last Names
  • Order by selection in List view of OpenERP 7.0
  • Reading input values in ipython notebook
  • List of dictionaries - how to read a specific value in a dictionary
  • writing os.system output to file
  • Create dictionary from points list and multiple attribute lists
  • How to write a table line by line with for loop
  • Map projection and forced interpolation
  • Django FBV's "render_to_response" equivalent in Class-Based-View?
  • Paramiko raises "SFTPError: Garbage packet received"
  • python pandas operations on columns
  • python list appending is not working
  • Speeding up matplotlib scatter plots
  • For each element of the list find closest date from a different list
  • How to prepend new rows at the beginning of an existing csv file?
  • how to make database robust to process kills with sqlite postgress and sqlalchemy?
  • finding a set of ranges that a number fall in
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org