logo
down
shadow

How to print only a certain part of a list?


How to print only a certain part of a list?

By : user7447490
Date : October 17 2020, 03:08 PM
wish help you to fix your issue Using the algorithm recommended in the comments:
code :
my_list = ['DOG', 'CAT', 'LION', 'TIGER', 'CAT', 'DOG', 'LION', 'LION', 'TIGER']

# get the indicies of each element 'CAT' from the list
cat_indicies = [i for i, x in enumerate(my_list) if x == "CAT"]

# list comprehension for all elements between first and second instance of 'CAT'
my_list1 = [my_list[i] for i in range(*cat_indicies)]

# list of all elements starting from second instance of 'CAT'
my_list2 = my_list[cat_indicies[-1]::]

print(my_list1)  # ['CAT', 'LION', 'TIGER']
print(my_list2)  # ['CAT', 'DOG', 'LION', 'LION', 'TIGER']


Share : facebook icon twitter icon
Print only part of a tuple in list

Print only part of a tuple in list


By : Bartolome Marin Sanc
Date : March 29 2020, 07:55 AM
How to print part of item in a list?

How to print part of item in a list?


By : kekoa428
Date : March 29 2020, 07:55 AM
hop of those help? Assuming all the values keep that pattern, split and join back, ignoring last value in splitted array:
code :
l = ['Blake 4', 'Bolt 1', 'De Grasse 3', 'Gatlin 2', 'Simbine 5', 'Youssef Meite 6']
for x in l:
   print(' '.join(x.split()[:-1]))
import re
l = ['Blake 4', 'Bolt 1', 'De Grasse 3', 'Gatlin 2', 'Simbine 5', 'Youssef Meite 6']
for x in l:
    print(re.sub(' \d+', '', x))
How to print only a certain part of elements from a list in python?

How to print only a certain part of elements from a list in python?


By : Maga
Date : March 29 2020, 07:55 AM
Hope this helps So I have a list: , A simple way would be:
code :
list = ['13:57:09.273 0,Type=IsXover Count=4,mcuTs=0x000265C7,lp-isD=1', 
    '13:57:09.341 1,Type=Xover Count=47,mcuTs=0x0002660A,lp-isD=0',
    '13:57:15.389 0,Type=Xover Count=48,mcuTs=0x00027D87,lp-isD=1']

result = []
for string in list:
    for index, sub_string in enumerate(string.split(',')):
        if index == 1:
           result.append(sub_string[sub_string.find('over'):])

print(result) 
result = [sub_string[sub_string.find('over'):] for string in list for index, sub_string in enumerate(sub_string.split(',')) if index == 1]
print(result)
['over Count=4','over Count=47','over Count=48']
How do I use a number from a complex list as a heading / How do I print only part of a list that matches a certain value

How do I use a number from a complex list as a heading / How do I print only part of a list that matches a certain value


By : user2274014
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further You could use itertools.groupby to group the "inputs" by your "sets" numbers like this:
code :
from itertools import groupby
from operator import itemgetter


set_history = [[[12, 11, 1], 1], [[12, 6, 2], 1], [[8, 7, 1], 1], [[6, 6, 1], 2]]

for key, group in groupby(set_history, key=itemgetter(1)):
    print(f'Starting with set {key}:')
    for item in group:
        print(*item[0], sep=", ")
Starting with set 1:
12, 11, 1
12, 6, 2
8, 7, 1
Starting with set 2:
6, 6, 1
Print part of a 2D list

Print part of a 2D list


By : user2532232
Date : March 29 2020, 07:55 AM
Related Posts Related Posts :
  • How to equalize the size of two numpy arrays
  • Hive Server 2 error on python connect with hiveserver2
  • TypeError: argument 1 must have a "write" method
  • Python, read uart and post to MQTT, has extra spaces
  • test getting skipped in pytest
  • Python: from list to enumerated list to pass to lambda reduce function
  • f[1] raised exception TypeError: 'int' object is not subscriptable
  • how to make a random list in python3
  • Keeping Python from spacing after breaking a line when printing a List
  • Create a temporary table in python to join with a sql table
  • How to update a specific line in a file in python?
  • Google PubSub python client returning StatusCode.UNAVAILABLE
  • Error in regex substring match in a list in python
  • Pandas groupby() on one column and then sum on another
  • How to use multiple "or" in python code
  • spider = cls(*args, **kwargs) TypeError: __init__() got an unexpected keyword argument '_job'
  • Python, Django LDAP: detecting Authentication failed reasoning
  • Is it good to define a function in a function python
  • Zeep : Need to convert this sample soap request
  • How to render a template and send a file simultaneously with flask
  • Create new column in dataframe with match values from other dataframe
  • Group the values using one column and return the one having max value in other column using pandas dataframe
  • Python3 tkinter analog gauge
  • How to display all the data which is groupby "Cause" from 1981 to 1992 in python pandas?
  • Scrape content in json format - Python
  • How to replace pandas columns with the same name in to another dataframe?
  • Trying to build a proxy with aiohttp
  • Compound interest calculator loops
  • how to create a raw string when it's last character is a `\` in python
  • Scrapy - how can I split the data in this table?
  • Making post requests in python
  • How can I manipulate shapes (colors) in PowerPoint using Python and win32com.client?
  • Get sorted output for os.walk()
  • Pandas Mapping Column
  • How to remove border of microsoft word in text image in opencv with python?
  • why not always use map if its faster than the rest (list comprehension, loop (various variants))?
  • Trying to download a directory with requests
  • Django Django model “doesn't declare an explicit app_label” because of project's init.py file
  • Comparing 2 arrays using numpy and allocating values to a third array
  • How to do change the recieved SQL output format, in python
  • Python: how to write binary data to the stdout so that bash script can use process substitution?
  • How to combine two lists to get a new list of the shape as mentioned in description
  • Run-time Complexity for two algorithms (Big O notation calculation)
  • jupyter SSL: WRONG_VERSION_NUMBER
  • Import of csv data rows and columns when specyfing delimiter
  • Error in texting automated message in whatsapp using python
  • Why my model work ok with test data from train_test_split while doesn't with the new data?
  • Python Networkx: How to "redraw" graph after every iteration?
  • How to read a large json in pandas?
  • Protobuf Message Constructor
  • Keras: Concatenating metadata into a CNN
  • pyqtgraph get text of node and change color on MouseClick
  • how to handover *args to pathos' amap
  • Merge returns NaN except for first row
  • Seaborn graphing: Highlighting single data point in jointplot
  • ValueError: Metric 'cosine' not valid for algorithm 'ball_tree' when using sklearn TSNE
  • How to convert the strings in sublists into integer faster without forloop in python?
  • removing characters like '\u0152\xe6' from string
  • How do i get new line(row wise) output in SQL query using python
  • Saving an uploaded file to disk doesn't work in Flask
  • shadow
    Privacy Policy - Terms - Contact Us © soohba.com