Sponsored Content
Top Forums Programming Search or find a element inside list python Post 303033242 by Priya Amaresh on Tuesday 2nd of April 2019 04:54:37 AM
Old 04-02-2019
Search or find a element inside list python

I have a list as follows:
Code:
[u'12:13-internet-wifi-primary', u'26:27-broadcom-wifi']


From this i need to grep the element using keyword as "primary" and return output as

Code:
12:13-internet-wifi-primary

i used as follows
Code:
                    if (i <= (len(system_info['Ad_List']))):
                        ss = system_info['Ad_List']
                        print type(ss)
                        searchObj = "primary"
                        #if 'primary' in ss:
                        if any(word in searchObj for word in ss):
                            print "inside if"
                            print searchObj
                        else:
                            print "inside else... No search obj"

Always it gets into else part.. Smilie
How to do it.. split,find are not list attributes
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Awk search for a element in the list of strings

Hi, how do I match a particular element in a list and replace it with blank? awk 'sub///' $FILE list="AL, AK, AZ, AR, CA, CO, CT, DE, FL, GA, HI, ID, IL, IN, IA, KS, KY, LA, ME, MD, MA, MI, MN, MS, MO, MT, NE, NV, NH, NJ, NM, NY, NC, ND, OH, OK, OR, PA, RI, SC, SD, TN, TX, UT, VT, VA, WA,... (2 Replies)
Discussion started by: grossgermany
2 Replies

2. UNIX for Dummies Questions & Answers

script to search patterns inside list of files

>testfile while read x do if then echo $x >> testfile else fi if then echo $x >> testfile else fi done < list_of_files is there any efficient way to search abc.dml and xyz.dml ? (2 Replies)
Discussion started by: dr46014
2 Replies

3. Shell Programming and Scripting

Need to find root element name of XML file

Given this XML: <?xml version="1.0"?> <catalog> <cd> <title>Empire Burlesque</title> <artist>Bob Dylan</artist> <country>USA</country> <company>Columbia</company> <price>10.90</price> <year>1985</year> </cd> <cd> <title>Hide your heart</title> ... (2 Replies)
Discussion started by: ricksj
2 Replies

4. Shell Programming and Scripting

Find if XML element has a matching required element

I want to check if every <Part> element has corresponding <Description> in this sample XML. ....<Lot Of XML> <Inv lineNumber="2"> <Item> ... (4 Replies)
Discussion started by: kchinnam
4 Replies

5. Shell Programming and Scripting

awk Search Array Element Return Index

Can you search AWK array elements and return each index value for that element. For example an array named car would have index make and element engine. I want to return all makes with engine size 1.6. Array woulld look like this: BMW 1.6 BMW 2.0 BMW 2.5 AUDI 1.8 AUDI 1.6 ... (11 Replies)
Discussion started by: u20sr
11 Replies

6. Shell Programming and Scripting

Find first n element by matching IDs

Hi All I have a problem that I am not able to resolve. Briefly, I have a file like this: ID_1 10 ID_2 15 ID_3 32 ID_4 45 ID_5 66 ID_6 79 ID_7 88This file is numerically ordered for the 2th column. And another file containing a list of IDs(just one in this example) ID_4What I... (7 Replies)
Discussion started by: giuliangiuseppe
7 Replies

7. Shell Programming and Scripting

sed command inside paramiko python

Hi I am trying to execute a sed command inside paramiko which finds and deletes the particular string from a file But sed command doesnt work inside paramiko python machine=qwe dssh = paramiko.SSHClient() dssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) try: ... (4 Replies)
Discussion started by: Priya Amaresh
4 Replies

8. Shell Programming and Scripting

Find common values in python list in ordered format

Hello All, There are various codes available to find the intersection between two sets in python. But my case is the following: I want to find the continual common pattern in different lists compared to list1. (i have underlined the longest common patterns in set a and set b) a = 2, 3, 5,... (1 Reply)
Discussion started by: Zam_1234
1 Replies

9. Shell Programming and Scripting

How to insert a CSV within xml element tag using Python?

Hi Team, I have a CSV file which I have to read through and needs to insert the content within an XML file using Python ONLY ( as most of the code base we have in python only). I managed to find the first part, missing how to insert to XML under "specific" tags. cat input.csv... (0 Replies)
Discussion started by: panyam
0 Replies

10. Programming

Create a C source and compile inside Python 1.4.0 to 3.7.0 in Python for ALL? platforms...

Hi all... As you know I like making code backwards compatible for as many platforms as possible. This Python script was in fact dedicated for the AMIGA A1200 using Pythons 1.4.0, 1.5.2, 1.6.0, 2.0.1, and 2.4.6 as that is all we have for varying levels of upgrades from a HDD and 4MB FastRam... (1 Reply)
Discussion started by: wisecracker
1 Replies
PYTHON(1)						    BSD General Commands Manual 						 PYTHON(1)

NAME
python, pythonw -- an interpreted, interactive, object-oriented programming language SYNOPSIS
python ... pythonw ... DESCRIPTION
To support multiple versions, the programs named python and pythonw now just select the real version of Python to run, depending on various settings. (As of Python 2.5, python and pythonw are interchangeable; both execute Python in the context of an application bundle, which means they have access to the Graphical User Interface; thus both can, when properly programmed, display windows, dialogs, etc.) The current supported versions are 2.6 and 2.7, with the default being 2.6. Use % man python2.6 % man python2.7 % man pythonw2.6 % man pythonw2.7 to see the man page for a specific version. Without a version specified, % man pydoc and the like, will show the man page for the (unmodified) default version of Python (2.6). To see the man page for a specific version, use, for example, % man pydoc2.7 CHANGING THE DEFAULT PYTHON
Using % defaults write com.apple.versioner.python Version 2.7 will make version 2.7 the user default when running the both the python and pythonw commands (versioner is the internal name of the version- selection software used). To set a system-wide default, replace 'com.apple.versioner.python' with '/Library/Preferences/com.apple.versioner.python' (admin privileges will be required). The environment variable VERSIONER_PYTHON_VERSION can also be used to set the python and pythonw version: % export VERSIONER_PYTHON_VERSION=2.7 # Bourne-like shells or % setenv VERSIONER_PYTHON_VERSION 2.7 # C-like shells % python ... This environment variable takes precedence over the preference file settings. 64-BIT SUPPORT Versions 2.6 and 2.7 support 64-bit execution (which is on by default). Like the version of Python, the python command can select between 32 and 64-bit execution (when both are available). Use: % defaults write com.apple.versioner.python Prefer-32-Bit -bool yes to make 32-bit execution the user default (using '/Library/Preferences/com.apple.versioner.python' will set the system-wide default). The environment variable VERSIONER_PYTHON_PREFER_32_BIT can also be used (has precedence over the preference file): % export VERSIONER_PYTHON_PREFER_32_BIT=yes # Bourne-like shells or % setenv VERSIONER_PYTHON_PREFER_32_BIT yes # C-like shells Again, the preference setting and environmental variable applies to both python and pythonw. USING A SPECIFIC VERSION
Rather than using the python command, one can use a specific version directly. For example, running python2.7 from the command line will run the 2.7 version of Python, independent of what the default version of Python is. One can use a specific version of Python on the #! line of a script, but that may have portability and future compatibility issues. Note that the preference files and environment variable that apply to the python command, do not apply when running a specific version of Python. In particular, running python2.6 will always default to 64-bit execution (unless one uses the arch(1) command to specifically select a 32-bit architecture). SEE ALSO
python2.6(1), python2.7(1), pythonw2.6(1), pythonw2.7(1), arch(1) BSD
Aug 10, 2008 BSD
All times are GMT -4. The time now is 06:33 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy